aboutsummaryrefslogtreecommitdiffstats
path: root/vespamalloc/src/tests/test.cpp
blob: e19e119bb33c63f149c21705098e8b01fadbb9c5 (plain) (blame)
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
61
62
63
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/fastos/thread.h>
#include <cstdlib>
#include <cstdio>

namespace vespamalloc {
void info();
}

void testbigblocks(size_t count, size_t sz)
{
    for (size_t i=0; i < count; i++) {
        char * a = new char[sz];
        delete [] a;
        a = new char [sz-1];
        delete [] a;
    }
}

void testdd()
{
    char * a = (char *)malloc(0x1003);
    free(a);
}

class Thread : public FastOS_Runnable
{
private:
    void Run(FastOS_ThreadInterface * ti, void * arg) override;
};

int main(int, char *[])
{
    FastOS_ThreadPool threadPool(512*1024);
    printf("Main stack(%p)\n", &threadPool);
    Thread context;

    FastOS_ThreadInterface * th[4];
    for (size_t i=0; i<sizeof(th)/sizeof(th[0]); i++) {
        th[i] = threadPool.NewThread(&context);
    }
    for (size_t i=0; i<sizeof(th)/sizeof(th[0]); i++) {
        th[i]->Join();
        delete th[i];
    }

    return 0;
}

void Thread::Run(FastOS_ThreadInterface *, void *)
{
    char * a = new char [100];
    delete [] a;
    char * b;

    testbigblocks(1, 0x800003);
    testbigblocks(64000, 0x200003);
    for (size_t i=0; i<100;i++) a = new char[400];
    testdd();
    b = new char[200];
    (void)b;
}