~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/tests/expr.c

Version: ~ [ linux-6.1-rc7 ] ~ [ linux-6.0.10 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.80 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.156 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.225 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.267 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.300 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.334 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.302 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 #include "util/debug.h"
  3 #include "util/expr.h"
  4 #include "tests.h"
  5 #include <stdlib.h>
  6 
  7 static int test(struct parse_ctx *ctx, const char *e, double val2)
  8 {
  9         double val;
 10 
 11         if (expr__parse(&val, ctx, &e))
 12                 TEST_ASSERT_VAL("parse test failed", 0);
 13         TEST_ASSERT_VAL("unexpected value", val == val2);
 14         return 0;
 15 }
 16 
 17 int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused)
 18 {
 19         const char *p;
 20         const char **other;
 21         double val;
 22         int ret;
 23         struct parse_ctx ctx;
 24         int num_other;
 25 
 26         expr__ctx_init(&ctx);
 27         expr__add_id(&ctx, "FOO", 1);
 28         expr__add_id(&ctx, "BAR", 2);
 29 
 30         ret = test(&ctx, "1+1", 2);
 31         ret |= test(&ctx, "FOO+BAR", 3);
 32         ret |= test(&ctx, "(BAR/2)%2", 1);
 33         ret |= test(&ctx, "1 - -4",  5);
 34         ret |= test(&ctx, "(FOO-1)*2 + (BAR/2)%2 - -4",  5);
 35         ret |= test(&ctx, "1-1 | 1", 1);
 36         ret |= test(&ctx, "1-1 & 1", 0);
 37         ret |= test(&ctx, "min(1,2) + 1", 2);
 38         ret |= test(&ctx, "max(1,2) + 1", 3);
 39         ret |= test(&ctx, "1+1 if 3*4 else 0", 2);
 40 
 41         if (ret)
 42                 return ret;
 43 
 44         p = "FOO/0";
 45         ret = expr__parse(&val, &ctx, &p);
 46         TEST_ASSERT_VAL("division by zero", ret == 1);
 47 
 48         p = "BAR/";
 49         ret = expr__parse(&val, &ctx, &p);
 50         TEST_ASSERT_VAL("missing operand", ret == 1);
 51 
 52         TEST_ASSERT_VAL("find other",
 53                         expr__find_other("FOO + BAR + BAZ + BOZO", "FOO", &other, &num_other) == 0);
 54         TEST_ASSERT_VAL("find other", num_other == 3);
 55         TEST_ASSERT_VAL("find other", !strcmp(other[0], "BAR"));
 56         TEST_ASSERT_VAL("find other", !strcmp(other[1], "BAZ"));
 57         TEST_ASSERT_VAL("find other", !strcmp(other[2], "BOZO"));
 58         TEST_ASSERT_VAL("find other", other[3] == NULL);
 59         free((void *)other);
 60 
 61         return 0;
 62 }
 63 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp