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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/powerpc/stringloops/strlen.c

Version: ~ [ linux-5.1-rc5 ] ~ [ linux-5.0.7 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.34 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.111 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.168 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.178 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.138 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.65 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 #include <malloc.h>
  3 #include <stdlib.h>
  4 #include <string.h>
  5 #include <time.h>
  6 #include "utils.h"
  7 
  8 #define SIZE 256
  9 #define ITERATIONS 1000
 10 #define ITERATIONS_BENCH 100000
 11 
 12 int test_strlen(const void *s);
 13 
 14 /* test all offsets and lengths */
 15 static void test_one(char *s)
 16 {
 17         unsigned long offset;
 18 
 19         for (offset = 0; offset < SIZE; offset++) {
 20                 int x, y;
 21                 unsigned long i;
 22 
 23                 y = strlen(s + offset);
 24                 x = test_strlen(s + offset);
 25 
 26                 if (x != y) {
 27                         printf("strlen() returned %d, should have returned %d (%p offset %ld)\n", x, y, s, offset);
 28 
 29                         for (i = offset; i < SIZE; i++)
 30                                 printf("%02x ", s[i]);
 31                         printf("\n");
 32                 }
 33         }
 34 }
 35 
 36 static void bench_test(char *s)
 37 {
 38         struct timespec ts_start, ts_end;
 39         int i;
 40 
 41         clock_gettime(CLOCK_MONOTONIC, &ts_start);
 42 
 43         for (i = 0; i < ITERATIONS_BENCH; i++)
 44                 test_strlen(s);
 45 
 46         clock_gettime(CLOCK_MONOTONIC, &ts_end);
 47 
 48         printf("len %3.3d : time = %.6f\n", test_strlen(s), ts_end.tv_sec - ts_start.tv_sec + (ts_end.tv_nsec - ts_start.tv_nsec) / 1e9);
 49 }
 50 
 51 static int testcase(void)
 52 {
 53         char *s;
 54         unsigned long i;
 55 
 56         s = memalign(128, SIZE);
 57         if (!s) {
 58                 perror("memalign");
 59                 exit(1);
 60         }
 61 
 62         srandom(1);
 63 
 64         memset(s, 0, SIZE);
 65         for (i = 0; i < SIZE; i++) {
 66                 char c;
 67 
 68                 do {
 69                         c = random() & 0x7f;
 70                 } while (!c);
 71                 s[i] = c;
 72                 test_one(s);
 73         }
 74 
 75         for (i = 0; i < ITERATIONS; i++) {
 76                 unsigned long j;
 77 
 78                 for (j = 0; j < SIZE; j++) {
 79                         char c;
 80 
 81                         do {
 82                                 c = random() & 0x7f;
 83                         } while (!c);
 84                         s[j] = c;
 85                 }
 86                 for (j = 0; j < sizeof(long); j++) {
 87                         s[SIZE - 1 - j] = 0;
 88                         test_one(s);
 89                 }
 90         }
 91 
 92         for (i = 0; i < SIZE; i++) {
 93                 char c;
 94 
 95                 do {
 96                         c = random() & 0x7f;
 97                 } while (!c);
 98                 s[i] = c;
 99         }
100 
101         bench_test(s);
102 
103         s[16] = 0;
104         bench_test(s);
105 
106         s[8] = 0;
107         bench_test(s);
108 
109         s[4] = 0;
110         bench_test(s);
111 
112         s[3] = 0;
113         bench_test(s);
114 
115         s[2] = 0;
116         bench_test(s);
117 
118         s[1] = 0;
119         bench_test(s);
120 
121         return 0;
122 }
123 
124 int main(void)
125 {
126         return test_harness(testcase, "strlen");
127 }
128 

~ [ 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