Commit f10a014a authored by jan.koester's avatar jan.koester
Browse files

test

parent 1bad10de
Loading
Loading
Loading
Loading
+12 −7
Changes for src/test/e2e/thread_reclaim_test.cpp: 12 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -34,13 +34,14 @@ static int count_maps() {
    return n;
}

static long rss_kb() {
static long status_kb(const char* key) {
    FILE* f = fopen("/proc/self/status", "r");
    if (!f) return -1;
    long kb = -1;
    size_t n = strlen(key);
    char line[256];
    while (fgets(line, sizeof line, f))
        if (strncmp(line, "VmRSS:", 6) == 0) { kb = atol(line + 6); break; }
        if (strncmp(line, key, n) == 0) { kb = atol(line + n); break; }
    fclose(f);
    return kb;
}
@@ -100,15 +101,19 @@ int main() {
    for (int kind = 0; kind < 4; kind++) {
        CHECK(run_round(kind, N) == 0, "thread creation failed");
        int maps0 = count_maps();
        long rss0 = rss_kb();
        long vm0 = status_kb("VmSize:");
        long rss0 = status_kb("VmRSS:");
        CHECK(run_round(kind, N) == 0, "thread creation failed");
        CHECK(run_round(kind, N) == 0, "thread creation failed");
        int maps1 = count_maps();
        long rss1 = rss_kb();
        printf("%s: maps %d -> %d, rss %ld -> %ld kB\n",
               names[kind], maps0, maps1, rss0, rss1);
        /* leaked, each of the 600 threads cost a mapping and ~50 kB */
        long vm1 = status_kb("VmSize:");
        long rss1 = status_kb("VmRSS:");
        printf("%s: maps %d -> %d, vm %ld -> %ld kB, rss %ld -> %ld kB\n",
               names[kind], maps0, maps1, vm0, vm1, rss0, rss1);
        /* a leaked stack is 16 MB of address space; adjacent leaked
         * mappings merge, so their count alone proves nothing */
        CHECK(maps1 - maps0 < 20, "mappings grow with every thread");
        CHECK(vm1 - vm0 < 64 * 1024, "address space grows with every thread");
        CHECK(rss1 - rss0 < 2048, "resident size grows with every thread");
    }