// SPDX-License-Identifier: GPL-2.0 /* * sstcompr_test - userspace compress hammer for SOC-MR-02 verification. * * cycle [sleep_ms] : n times { open comprC*D -> SET_PARAMS(mp3) -> * START -> sleep -> close } * hold : one open->params->start, HWSYNC/POINTER loop * (fd alive across modprobe -r). * still : open/close only (no set_params -> callbacks * never armed) - negative control. * * SET_PARAMS arms the REAL sst_platform_compr_set_params path which * registers compr_cb=sst_compr_fragment_elapsed / * drain_notify=sst_drain_notify (both with cstream) into the harness's * captured slot; the harness kthread fires them across close(). */ #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include static const char *dev = "/dev/snd/comprC0D1"; static int msleep(int ms) { struct timespec ts = { .tv_sec = ms / 1000, .tv_nsec = (long)(ms % 1000) * 1000000L }; return nanosleep(&ts, NULL); } static int do_open(void) { int fd = open(dev, O_WRONLY); if (fd < 0) { fprintf(stderr, "open %s failed: %s\n", dev, strerror(errno)); return -1; } return fd; } static int set_params(int fd) { struct snd_compr_params *p = calloc(1, sizeof(*p)); if (!p) return -1; p->buffer.fragment_size = 4096; p->buffer.fragments = 8; p->codec.id = SND_AUDIOCODEC_MP3; p->codec.ch_in = 2; p->codec.ch_out = 2; p->codec.sample_rate = 44100; p->codec.bit_rate = 128; p->codec.profile = 0; /* mp3: MPEG-1 layer III */ p->codec.level = 0; if (ioctl(fd, SNDRV_COMPRESS_SET_PARAMS, p) < 0) { perror("SET_PARAMS"); free(p); return -1; } free(p); if (ioctl(fd, SNDRV_COMPRESS_START) < 0) { perror("START"); return -1; } return 0; } static int cycle(int n, int sleep_ms) { int i, fd; for (i = 0; i < n; i++) { fd = do_open(); if (fd < 0) return 1; if (set_params(fd) == 0) msleep(sleep_ms); close(fd); if ((i % 25) == 0) printf("compr cycle %d/%d done\n", i + 1, n); } printf("compr cycle: %d rounds done\n", n); return 0; } static int hold(int seconds) { int fd, k; fd = do_open(); if (fd < 0) return 1; if (set_params(fd)) return 1; printf("compr hold: RUNNING fd=%d for %ds\n", fd, seconds); for (k = 0; k < seconds * 10; k++) msleep(100); printf("compr hold: closing fd (release vs snd_compr_free race)\n"); close(fd); return 0; } static int still(void) { int i, fd; for (i = 0; i < 200; i++) { fd = do_open(); if (fd < 0) return 1; close(fd); /* no SET_PARAMS -> callbacks never armed */ } printf("compr still: 200 open/close done (callbacks never armed)\n"); return 0; } int main(int argc, char **argv) { if (argc >= 3 && !strcmp(argv[1], "cycle")) return cycle(atoi(argv[2]), argc >= 4 ? atoi(argv[3]) : 100); if (argc >= 3 && !strcmp(argv[1], "hold")) return hold(atoi(argv[2])); if (argc >= 2 && !strcmp(argv[1], "still")) return still(); fprintf(stderr, "usage: %s cycle [ms] | hold | still\n", argv[0]); return 2; }