瀏覽代碼

memory test using greatest

Thomas Buck 10 年之前
父節點
當前提交
4c6d8f2a0f
共有 5 個文件被更改,包括 45 次插入121 次删除
  1. 3
    0
      ChangeLog
  2. 1
    1
      src/Render.cpp
  3. 1
    1
      src/Texture.cpp
  4. 12
    12
      src/memory_test.cpp
  5. 28
    107
      test/memory_test.cpp

+ 3
- 0
ChangeLog 查看文件

@@ -5,6 +5,9 @@
5 5
 
6 6
  OpenRaider (0.1.2) xythobuz <xythobuz@xythobuz.de>
7 7
 
8
+	[ 20140201 ]
9
+	* Rewrote Memory Unit Test using greatest
10
+
8 11
 	[ 20140131 ]
9 12
 	* All unit tests buildable again and no more warnings
10 13
 

+ 1
- 1
src/Render.cpp 查看文件

@@ -259,7 +259,7 @@ void Render::initTextures(char *textureDir, unsigned int *numLoaded,
259 259
                     ++numTextures;
260 260
                 }
261 261
 
262
-    // Werid that it isn't linear, must be some storage deal in Texture
262
+    // Weird that it isn't linear, must be some storage deal in Texture
263 263
     // I forgot about Id allocation
264 264
     *nextId = font_id;
265 265
 

+ 1
- 1
src/Texture.cpp 查看文件

@@ -262,7 +262,7 @@ int Texture::loadFontTTF(const char *filename,
262 262
     if (texture)
263 263
     {
264 264
 #ifdef DUMP_TTF_TGA
265
-        FILE *f = fopen("font.tga", "wb");
265
+        FILE *f = fopen("ttf_font.tga", "wb");
266 266
         if (f)
267 267
         {
268 268
             tga_save(f, texture->texture, 256, 256, 4);

+ 12
- 12
src/memory_test.cpp 查看文件

@@ -12,6 +12,8 @@
12 12
 #define UNIT_TEST_MEMORY
13 13
 #include <memory_test.h>
14 14
 
15
+#define DEBUG_MEMORY_ERROR_OFF
16
+
15 17
 bool tree_check(rbtree_t *tree, const char *file, int line)
16 18
 {
17 19
     bool ret = true;
@@ -838,30 +840,30 @@ void display_memory_usage()
838 840
     printf("Memory usage summary:\n");
839 841
 
840 842
     printf(" Tracked program memory    : %lu bytes \t(%.2f MB)\n",
841
-            MEMORY_USED, (double)MEMORY_USED / 1024000.0);
843
+            MEMORY_USED, (double)MEMORY_USED / 1048576.0);
842 844
     printf(" Untracked overhead memory : %lu bytes \t(%.2f MB)\n",
843
-            MEMORYA_USED, (double)MEMORYA_USED / 1024000.0);
845
+            MEMORYA_USED, (double)MEMORYA_USED / 1048576.0);
844 846
     printf(" Untracked m-string memory : %lu bytes\n",
845 847
             MEMORYC_USED);
846 848
 
847 849
     printf("\n Total accounted memory    : %lu bytes \t(%.2f MB)\n",
848 850
             MEMORY_USED + MEMORYA_USED + MEMORYC_USED,
849
-            (double)(MEMORY_USED + MEMORYA_USED + MEMORYC_USED) / 1024000.0);
851
+            (double)(MEMORY_USED + MEMORYA_USED + MEMORYC_USED) / 1048576.0);
850 852
 
851 853
     printf("------------------------------------------------------------\n");
852 854
 
853 855
     printf("Memory max usage summary:\n");
854 856
 
855 857
     printf(" Tracked program memory    : %lu bytes \t(%.2f MB)\n",
856
-            MAX_MEMORY_USED, (double)MAX_MEMORY_USED / 1024000.0);
858
+            MAX_MEMORY_USED, (double)MAX_MEMORY_USED / 1048576.0);
857 859
     printf(" Untracked overhead memory : %lu bytes \t(%.2f MB)\n",
858
-            MAX_MEMORYA_USED, (double)MAX_MEMORYA_USED / 1024000.0);
860
+            MAX_MEMORYA_USED, (double)MAX_MEMORYA_USED / 1048576.0);
859 861
     printf(" Untracked m-string memory : %lu bytes\n",
860 862
             MAX_MEMORYC_USED);
861 863
 
862 864
     printf("\n Total accounted memory    : %lu bytes \t(%.2f MB)\n",
863 865
             MAX_MEMORY_USED + MAX_MEMORYA_USED + MAX_MEMORYC_USED,
864
-            (double)(MAX_MEMORY_USED + MAX_MEMORYA_USED + MAX_MEMORYC_USED) / 1024000.0);
866
+            (double)(MAX_MEMORY_USED + MAX_MEMORYA_USED + MAX_MEMORYC_USED) / 1048576.0);
865 867
 
866 868
     printf("============================================================\n");
867 869
 }
@@ -869,16 +871,14 @@ void display_memory_usage()
869 871
 
870 872
 void dump_memory_report()
871 873
 {
872
-    int i;
873
-
874
-
875 874
     printf("\n============================================================\n");
876 875
     printf(" Memory status report\n");
877 876
     printf("============================================================\n");
878 877
     printf("Memory tracking table:\n");
879
-    i = tree_print(MEMORY_INFO, (void (*)(void *))&__print_meminfo);
880
-    printf("%i records, %lu bytes each : %lu bytes\n",
881
-            i, sizeof(meminfo_t), i * sizeof(meminfo_t));
878
+    int i = tree_print(MEMORY_INFO, (void (*)(void *))&__print_meminfo);
879
+    if (i != 0) {
880
+        printf("%i records, %lu bytes each : %lu bytes\n", i, sizeof(meminfo_t), i * sizeof(meminfo_t));
881
+    }
882 882
     display_memory_usage();
883 883
     printf("============================================================\n\n");
884 884
 }

+ 28
- 107
test/memory_test.cpp 查看文件

@@ -3,12 +3,13 @@
3 3
  * Memory testing Toolkit Unit test
4 4
  *
5 5
  * \author Mongoose
6
+ * \author xythobuz
6 7
  */
7 8
 
8 9
 #include <string.h>
9 10
 #include <stdio.h>
10 11
 #include <stdlib.h>
11
-
12
+#include "greatest.h"
12 13
 #include <memory_test.h>
13 14
 
14 15
 extern rbtree_t *MEMORY_INFO;
@@ -19,47 +20,38 @@ extern long MEMORYC_USED;
19 20
 extern long MAX_MEMORY_USED;
20 21
 extern long MAX_MEMORYA_USED;
21 22
 extern long MAX_MEMORYC_USED;
22
-
23 23
 void tree_valid_report(rbtree_t *root);
24 24
 
25
-#define PRINT_TEST_BREAK_LINE   printf("\n############################################################\n\n");
26
-
27
-int memory_test_unit_test() {
28
-    int *i, *j, *k, *l, *m, *n, *o;
29
-
30
-    PRINT_TEST_BREAK_LINE
31
-        printf("Memory test\n");
32
-    PRINT_TEST_BREAK_LINE
33
-
34
-    i = new int;
35
-    printf(">\ti = new int; (%p)  %s:%i\n", i, __FILE__, __LINE__);
25
+TEST singleInteger() {
26
+    int *i = new int;
27
+    printf("\n>\ti = new int; (%p)  %s:%i\n", i, __FILE__, __LINE__);
36 28
     dump_memory_report();
37 29
     tree_valid_report(MEMORY_INFO);
38
-
39 30
     delete i;
40 31
     printf(">\tdelete i; (%p)  %s:%i\n", i, __FILE__, __LINE__);
41 32
     dump_memory_report();
42 33
     tree_valid_report(MEMORY_INFO);
34
+    PASS();
35
+}
43 36
 
44
-    PRINT_TEST_BREAK_LINE
45
-
46
-    i = new int[3];
47
-    printf(">\ti = new int[3]; (%p)  %s:%i\n", i, __FILE__, __LINE__);
37
+TEST arrayInteger() {
38
+    int *i = new int[3];
39
+    printf("\n>\ti = new int[3]; (%p)  %s:%i\n", i, __FILE__, __LINE__);
48 40
     dump_memory_report();
49 41
     tree_valid_report(MEMORY_INFO);
50
-
51 42
     delete [] i;
52 43
     printf(">\tdelete [] i; (%p)  %s:%i\n", i, __FILE__, __LINE__);
53 44
     dump_memory_report();
54 45
     tree_valid_report(MEMORY_INFO);
46
+    PASS();
47
+}
55 48
 
56
-    PRINT_TEST_BREAK_LINE
57
-
58
-    i = new int[3];
59
-    printf(">\ti = new int[3]; (%p)  %s:%i\n", i, __FILE__, __LINE__);
60
-    j = new int;
49
+TEST arrayCombinedInteger() {
50
+    int *i = new int[3];
51
+    printf("\n>\ti = new int[3]; (%p)  %s:%i\n", i, __FILE__, __LINE__);
52
+    int *j = new int;
61 53
     printf(">\tj = new int; (%p)  %s:%i\n", j, __FILE__, __LINE__);
62
-    k = new int[3];
54
+    int *k = new int[3];
63 55
     printf(">\tk = new int[3]; (%p)  %s:%i\n", k, __FILE__, __LINE__);
64 56
     dump_memory_report();
65 57
     tree_valid_report(MEMORY_INFO);
@@ -71,91 +63,20 @@ int memory_test_unit_test() {
71 63
     printf(">\tdelete [] k; (%p)  %s:%i\n", k, __FILE__, __LINE__);
72 64
     dump_memory_report();
73 65
     tree_valid_report(MEMORY_INFO);
66
+    PASS();
67
+}
74 68
 
75
-    PRINT_TEST_BREAK_LINE
76
-
77
-    i = new int[3];
78
-    printf(">\ti = new int[3]; (%p)  %s:%i\n", i, __FILE__, __LINE__);
79
-    j = new int;
80
-    printf(">\tj = new int; (%p)  %s:%i\n", j, __FILE__, __LINE__);
81
-    k = new int[3];
82
-    printf(">\tk = new int[3]; (%p)  %s:%i\n", k, __FILE__, __LINE__);
83
-    dump_memory_report();
84
-    tree_valid_report(MEMORY_INFO);
85
-    delete j;
86
-    printf(">\tdelete j; (%p)  %s:%i\n", j, __FILE__, __LINE__);
87
-    dump_memory_report();
88
-    tree_valid_report(MEMORY_INFO);
89
-    j = new int[3];
90
-    printf(">\tj = new int[3]; (%p)  %s:%i\n", j, __FILE__, __LINE__);
91
-    dump_memory_report();
92
-    tree_valid_report(MEMORY_INFO);
93
-    l = new int[3];
94
-    printf(">\tl = new int[3]; (%p)  %s:%i\n", l, __FILE__, __LINE__);
95
-    dump_memory_report();
96
-    tree_valid_report(MEMORY_INFO);
97
-    m = new int[3];
98
-    printf(">\tm = new int[3]; (%p)  %s:%i\n", m, __FILE__, __LINE__);
99
-    dump_memory_report();
100
-    tree_valid_report(MEMORY_INFO);
101
-
102
-    n = new int[3];
103
-    printf(">\tn = new int[3]; (%p)  %s:%i\n", n, __FILE__, __LINE__);
104
-    dump_memory_report();
105
-    tree_valid_report(MEMORY_INFO);
106
-
107
-    o = new int[3];
108
-    printf(">\to = new int[3]; (%p)  %s:%i\n", o, __FILE__, __LINE__);
109
-    dump_memory_report();
110
-    tree_valid_report(MEMORY_INFO);
111
-
112
-    delete [] k;
113
-    printf(">\tdelete [] k; (%p)  %s:%i\n", k, __FILE__, __LINE__);
114
-    dump_memory_report();
115
-    tree_valid_report(MEMORY_INFO);
116
-
117
-    delete [] j;
118
-    printf(">\tdelete [] j; (%p)  %s:%i\n", j, __FILE__, __LINE__);
119
-    dump_memory_report();
120
-    tree_valid_report(MEMORY_INFO);
121
-
122
-    delete [] l;
123
-    printf(">\tdelete [] l; (%p)  %s:%i\n", l, __FILE__, __LINE__);
124
-    dump_memory_report();
125
-    tree_valid_report(MEMORY_INFO);
126
-
127
-    delete [] m;
128
-    printf(">\tdelete [] m; (%p)  %s:%i\n", m, __FILE__, __LINE__);
129
-    dump_memory_report();
130
-    tree_valid_report(MEMORY_INFO);
131
-
132
-    delete [] n;
133
-    printf(">\tdelete [] n; (%p)  %s:%i\n", n, __FILE__, __LINE__);
134
-    dump_memory_report();
135
-    tree_valid_report(MEMORY_INFO);
136
-
137
-    delete [] o;
138
-    printf(">\tdelete [] o; (%p)  %s:%i\n", o, __FILE__, __LINE__);
139
-    dump_memory_report();
140
-    tree_valid_report(MEMORY_INFO);
141
-
142
-    delete [] i;
143
-    printf(">\tdelete [] i; (%p)  %s:%i\n", i, __FILE__, __LINE__);
144
-    dump_memory_report();
145
-    tree_valid_report(MEMORY_INFO);
146
-
147
-    PRINT_TEST_BREAK_LINE
148
-
149
-    return 0;
69
+SUITE(integerSuite) {
70
+    RUN_TEST(singleInteger);
71
+    RUN_TEST(arrayInteger);
72
+    RUN_TEST(arrayCombinedInteger);
150 73
 }
151 74
 
75
+GREATEST_MAIN_DEFS();
76
+
152 77
 int main(int argc, char *argv[]) {
153
-    if (argc != 1) {
154
-        printf("Usage:\n\t%s\n", argv[0]);
155
-        return 1;
156
-    } else {
157
-        printf("[memory_test test]\n");
158
-        return memory_test_unit_test();
159
-    }
78
+    GREATEST_MAIN_BEGIN();
79
+    RUN_SUITE(integerSuite);
80
+    GREATEST_MAIN_END();
160 81
 }
161 82
 

Loading…
取消
儲存