On Fri, Sep 07, 2012 at 07:43:45PM -0700, Ben Widawsky wrote:
> Signed-off-by: Ben Widawsky <b...@bwidawsk.net>
> ---

One small improvement would be nice:

[snip]

> +static void writeval(FILE *filp, int val)
> +{
> +     rewind(filp);
> +     fprintf(filp, "%d", val);
> +     fflush(filp);
> +}

Adding some assert here to check whether a write we expect to succeed
indeed worked, and that a write we expect to return -EINVAL indeed fails
with that error.
-Daniel

> +
> +#define fcur (readval(stuff[CUR].filp))
> +#define fmin (readval(stuff[MIN].filp))
> +#define fmax (readval(stuff[MAX].filp))
> +#define frp0 (readval(stuff[RP0].filp))
> +#define frp1 (readval(stuff[RP1].filp))
> +#define frpn (readval(stuff[RPn].filp))
> +
> +static void setfreq(int val)
> +{
> +     writeval(stuff[MIN].filp, val);
> +     writeval(stuff[MAX].filp, val);
> +}
> +
> +static void checkit(void)
> +{
> +     restore_assert(fmin <= fmax);
> +     restore_assert(fcur <= fmax);
> +     restore_assert(fmin <= fcur);
> +     restore_assert(frpn <= fmin);
> +     restore_assert(fmax <= frp0);
> +     restore_assert(frp1 <= frp0);
> +     restore_assert(frpn <= frp1);
> +     restore_assert(frp0 != 0);
> +     restore_assert(frp1 != 0);
> +}
> +
> +static void dumpit(void)
> +{
> +     struct junk *junk = stuff;
> +     do {
> +             printf("gt frequency %s (MHz):  %d\n", junk->name, 
> readval(junk->filp));
> +             junk++;
> +     } while(junk->name != NULL);
> +
> +     printf("\n");
> +}
> +
> +
> +int main(int argc, char *argv[])
> +{
> +     const int device = drm_get_card(0);
> +     struct junk *junk = stuff;
> +     int fd, ret;
> +
> +     if (argc > 1)
> +             verbose++;
> +
> +     /* Use drm_open_any to verify device existence */
> +     fd = drm_open_any();
> +     close(fd);
> +
> +     do {
> +             int val = -1;
> +             char *path;
> +             ret = asprintf(&path, sysfs_base_path, device, junk->name);
> +             assert(ret != -1);
> +             junk->filp = fopen(path, junk->mode);
> +             if (junk->filp == NULL) {
> +                     fprintf(stderr, "Kernel is too old. GTFO\n");
> +                     exit(77);
> +             }
> +             val = readval(junk->filp);
> +             assert(val >= 0);
> +             junk++;
> +     } while(junk->name != NULL);
> +
> +     origmin = fmin;
> +     origmax = fmax;
> +
> +     if (verbose)
> +             printf("Original min = %d\nOriginal max = %d\n", origmin, 
> origmax);
> +
> +     if (verbose)
> +             dumpit();
> +
> +     checkit();
> +     setfreq(fmin);
> +     if (verbose)
> +             dumpit();
> +     restore_assert(fcur == fmin);
> +     setfreq(fmax);
> +     if (verbose)
> +             dumpit();
> +     restore_assert(fcur == fmax);
> +     checkit();
> +
> +     /* And some errors */
> +     writeval(stuff[MIN].filp, frpn - 1);
> +     writeval(stuff[MAX].filp, frp0 + 1000);
> +     checkit();
> +
> +     writeval(stuff[MIN].filp, fmax + 1000);
> +     writeval(stuff[MAX].filp, fmin - 1);
> +     checkit();
> +
> +     writeval(stuff[MIN].filp, origmin);
> +     writeval(stuff[MAX].filp, origmax);
> +
> +     exit(EXIT_SUCCESS);
> +}
> -- 
> 1.7.12
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reply via email to