aboutsummaryrefslogtreecommitdiff
path: root/tests/core/test_memset.c
blob: 747765f2df5b0dae08d63d49534ec69750391b84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include <string.h>
#include <assert.h>

#define TOTAL 10240

#define TEST(size, type) { \
  for (int i = 0; i < TOTAL; i++) { \
    buffer[i] = i*seed; \
  } \
  memset(buffer+size%17, 0xA5, size); \
  int v = 0; \
  for (int i = 0; i < TOTAL; i++) { \
    v += buffer[i]; \
  } \
  printf("final %d:%d\n", size, v); \
}

int main() {
  #define RUN(type) \
  { \
    type buffer[TOTAL]; \
    volatile int seed = 123; \
    TEST(1, type); \
    TEST(2, type); \
    TEST(3, type); \
    TEST(4, type); \
    TEST(5, type); \
    TEST(6, type); \
    TEST(7, type); \
    TEST(8, type); \
    TEST(9, type); \
    TEST(10, type); \
    TEST(16, type); \
    TEST(32, type); \
    TEST(64, type); \
    TEST(128, type); \
    TEST(256, type); \
    TEST(512, type); \
    TEST(1024, type); \
    for (int x = 10; x < 100; x += 10) { TEST(x, type) }; \
  }
  printf("8\n");
  RUN(unsigned char);
  printf("16\n");
  RUN(unsigned short);
  printf("32\n");
  RUN(unsigned);
  return 1;
}