summaryrefslogtreecommitdiffstats
path: root/tests/memtest/memtest.c
blob: e7a260459bdc8d1baa95a450dd5af2673964ee8c (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
52
53
54
55
56
57
58
59
60

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "libmem.h"

int main(int argc, char** argv)
{
  void* obj;
  unsigned int addr1;
  unsigned int addr2;
  unsigned int addr3;
  unsigned int addr4;
  unsigned int addr5;
  int index;
  int rd;

  srand(time(0));
  obj = libmem_init(0x80000000, 64 * 1024 * 1024);
  for (index = 0; index < 256; index++)
  {
    rd = rand() & 0xffff;
    printf("1 rd %d\n", rd);
    addr1 = libmem_alloc(obj, rd);
    rd = rand() & 0xffff;
    printf("2 rd %d\n", rd);
    addr2 = libmem_alloc(obj, rd);
    rd = rand() & 0xffff;
    printf("3 rd %d\n", rd);
    addr3 = libmem_alloc(obj, rd);
    rd = rand() & 0xffff;
    printf("4 rd %d\n", rd);
    addr4 = libmem_alloc(obj, rd);
    addr5 = libmem_alloc(obj, rd);
    libmem_free(obj, addr1);
    printf("5\n");
    addr1 = libmem_alloc(obj, 64);
    printf("6\n");
    libmem_free(obj, addr3);
    printf("7\n");
    addr3 = libmem_alloc(obj, 64 * 1024);
    libmem_free(obj, addr5);
    addr5 = libmem_alloc(obj, 64 * 1024);
    printf("8\n");
    libmem_free(obj, addr1);
    printf("9\n");
    libmem_free(obj, addr2);
    printf("10\n");
    libmem_free(obj, addr3);
    libmem_free(obj, addr4);
    if (index == 255)
    {
      libmem_set_flags(obj, 1);
    }
    libmem_free(obj, addr5);
  }
  libmem_deinit(obj);
  return 0;
}