// SPDX-License-Identifier: GPL-2.0 // // kselftest configuration helpers for the hw specific configuration // // Original author: Jaroslav Kysela <perex@perex.cz> // Copyright (c) 2022 Red Hat Inc.
for (conf = conf_cards; conf; conf = conf->next) { if (conf->card == card) { if (msg)
ksft_print_msg("using hw card config %s for card %d\n",
conf->filename, card); return conf;
}
} return NULL;
}
staticvoid dump_config_tree(snd_config_t *top)
{
snd_output_t *out; int err;
err = snd_output_stdio_attach(&out, stdout, 0); if (err < 0)
ksft_exit_fail_msg("stdout attach\n"); if (snd_config_save(top, out))
ksft_exit_fail_msg("config save\n");
snd_output_close(out);
}
snd_config_t *conf_load_from_file(constchar *filename)
{
snd_config_t *dst;
snd_input_t *input; int err;
err = snd_input_stdio_open(&input, filename, "r"); if (err < 0)
ksft_exit_fail_msg("Unable to parse filename %s\n", filename);
err = snd_config_top(&dst); if (err < 0)
ksft_exit_fail_msg("Out of memory\n");
err = snd_config_load(dst, input);
snd_input_close(input); if (err < 0)
ksft_exit_fail_msg("Unable to parse filename %s\n", filename); return dst;
}
staticchar *sysfs_get(constchar *sysfs_root, constchar *id)
{ char path[PATH_MAX], link[PATH_MAX + 1]; struct stat sb;
ssize_t len; char *e; int fd;
if (id[0] == '/')
id++;
snprintf(path, sizeof(path), "%s/%s", sysfs_root, id); if (lstat(path, &sb) != 0) return NULL; if (S_ISLNK(sb.st_mode)) {
len = readlink(path, link, sizeof(link) - 1); if (len <= 0) {
ksft_exit_fail_msg("sysfs: cannot read link '%s': %s\n",
path, strerror(errno)); return NULL;
}
link[len] = '\0';
e = strrchr(link, '/'); if (e) return strdup(e + 1); return NULL;
} if (S_ISDIR(sb.st_mode)) return NULL; if ((sb.st_mode & S_IRUSR) == 0) return NULL;
fd = open(path, O_RDONLY); if (fd < 0) { if (errno == ENOENT) return NULL;
ksft_exit_fail_msg("sysfs: open failed for '%s': %s\n",
path, strerror(errno));
}
len = read(fd, path, sizeof(path)-1);
close(fd); if (len < 0)
ksft_exit_fail_msg("sysfs: unable to read value '%s': %s\n",
path, strerror(errno)); while (len > 0 && path[len-1] == '\n')
len--;
path[len] = '\0';
e = strdup(path); if (e == NULL)
ksft_exit_fail_msg("Out of memory\n"); return e;
}
staticbool sysfs_match(constchar *sysfs_root, snd_config_t *config)
{
snd_config_t *node, *path_config, *regex_config;
snd_config_iterator_t i, next; constchar *path_string, *regex_string, *v;
regex_t re;
regmatch_t match[1]; int iter = 0, ret;
snd_config_for_each(i, next, config) {
node = snd_config_iterator_entry(i); if (snd_config_search(node, "path", &path_config))
ksft_exit_fail_msg("Missing path field in the sysfs block\n"); if (snd_config_search(node, "regex", ®ex_config))
ksft_exit_fail_msg("Missing regex field in the sysfs block\n"); if (snd_config_get_string(path_config, &path_string))
ksft_exit_fail_msg("Path field in the sysfs block is not a string\n"); if (snd_config_get_string(regex_config, ®ex_string))
ksft_exit_fail_msg("Regex field in the sysfs block is not a string\n");
iter++;
v = sysfs_get(sysfs_root, path_string); if (!v) returnfalse; if (regcomp(&re, regex_string, REG_EXTENDED))
ksft_exit_fail_msg("Wrong regex '%s'\n", regex_string);
ret = regexec(&re, v, 1, match, 0);
regfree(&re); if (ret) returnfalse;
} return iter > 0;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.