On Tue, Oct 25, 2016 at 11:44:36PM +0300, Marius Vlad wrote:
> +int
> +igt_pkill(int sig, const char *comm)
> +{
> +     int err = 0;
> +     PROCTAB *proc;
> +     proc_t *proc_info;
> +
> +     proc = openproc(PROC_FILLCOM | PROC_FILLSTAT | PROC_FILLARG);
> +     igt_assert(proc != NULL);
> +
> +     while ((proc_info = readproc(proc, NULL))) {
> +             if (!strncasecmp(proc_info->cmd, comm, sizeof(proc_info->cmd))) 
> {
> +
> +                     if (kill(proc_info->tid, sig) < 0)
> +                             err = -1;

err = -errno;

(we like to keep kernel conventions where nicely applicable)

> +
> +                     freeproc(proc_info);
> +                     break;
> +             }
> +             freeproc(proc_info);
> +     }
> +
> +     closeproc(proc);
> +     return err;
> +}

> +int

bool

> +igt_kmod_is_loaded(const char *mod_name)
> +{
> +     struct kmod_list *mod, *list;
> +     struct kmod_ctx *ctx;
> +     int ret = 0;
> +
> +     ctx = kmod_new(NULL, NULL);
> +     igt_assert(ctx != NULL);
> +
> +     if (kmod_module_new_from_loaded(ctx, &list) < 0) {
> +             kmod_unref(ctx);
> +             return -1;

Too confusing! :)

        if (kmod_module_new_from_loaded(ctx, &list) < 0)
                goto out;

> +     }
> +
> +     kmod_list_foreach(mod, list) {
> +             struct kmod_module *kmod = kmod_module_get_module(mod);
> +             const char *kmod_name = kmod_module_get_name(kmod);
> +
> +             if (!strncasecmp(kmod_name, mod_name, strlen(kmod_name))) {

strncasecmp? So what happens if we load i915 and I915_bpo ?

> +                     kmod_module_unref(kmod);
> +                     ret = 1;
> +                     break;
> +             }
> +             kmod_module_unref(kmod);
> +     }
> +
> +     kmod_module_unref_list(list);

out:
> +     kmod_unref(ctx);
> +
> +     return ret;
> +}

> +int
> +igt_kmod_load(const char *mod_name, const char *opts)
> +{
> +     struct kmod_ctx *ctx;
> +     struct kmod_module *kmod;
> +     int err = 0;
> +
> +     ctx = kmod_new(NULL, NULL);
> +     igt_assert(ctx != NULL);
> +
> +
> +     err = kmod_module_new_from_name(ctx, mod_name, &kmod);
> +     if (err < 0) {
> +             goto out;
> +     }
> +
> +     err = kmod_module_insert_module(kmod, 0, opts);
> +     if (err < 0) {
> +             switch (err) {
> +             case -EEXIST:
> +                     igt_info("Module %s already inserted\n",
> +                              kmod_module_get_name(kmod));
> +                     err = -1;

Don't reduce the information, just return err; (as elsewhere)

Not sure if igt_info() makes sense, it will be noise for those expecting
and handling the error.

> +                     break;
> +             case -ENOENT:
> +                     igt_info("Unknown symbol in module %s or "
> +                              "unknown parameter\n",
> +                              kmod_module_get_name(kmod));
> +                     err = -1;
> +                     break;
> +             default:
> +                     igt_info("Could not insert %s (%s)\n",
> +                              kmod_module_get_name(kmod), strerror(-err));
> +                     err = -1;
> +                     break;
> +             }
> +     }
> +out:
> +     kmod_module_unref(kmod);
> +     kmod_unref(ctx);
> +
> +     return err;
> +}
> +

-- 
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reply via email to