Skip to content

Commit 9e7ee2e

Browse files
committed
tests: add standalone var management tests.
1 parent 203fe71 commit 9e7ee2e

File tree

5 files changed

+225
-0
lines changed

5 files changed

+225
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
obj/
2+
bin/
3+
src/gfx/*.c
4+
src/gfx/*.h
5+
src/gfx/*.8xv
6+
.DS_Store
7+
convimg.yaml.lst
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"transfer_files": [
3+
"bin/DEMO.8xp"
4+
],
5+
"target": {
6+
"name": "DEMO",
7+
"isASM": true
8+
},
9+
"sequence": [
10+
"action|launch",
11+
"delay|1000",
12+
"hashWait|1",
13+
"delay|100",
14+
"key|enter",
15+
"delay|250",
16+
"hashWait|2",
17+
"delay|100",
18+
"key|enter",
19+
"delay|250",
20+
"hashWait|3",
21+
"delay|100",
22+
"key|enter",
23+
"delay|250",
24+
"hashWait|4",
25+
"delay|100",
26+
"key|enter",
27+
"delay|250",
28+
"hashWait|5"
29+
],
30+
"hashes": {
31+
"1": {
32+
"description": "Before creating list",
33+
"start": "vram_start",
34+
"size": "vram_16_size",
35+
"expected_CRCs": [
36+
"8118A4A8"
37+
]
38+
},
39+
"2": {
40+
"description": "After creating list",
41+
"start": "vram_start",
42+
"size": "vram_16_size",
43+
"expected_CRCs": [
44+
"D74C55F7"
45+
]
46+
},
47+
"3": {
48+
"description": "After archiving list",
49+
"start": "vram_start",
50+
"size": "vram_16_size",
51+
"expected_CRCs": [
52+
"D4DD64A8"
53+
]
54+
},
55+
"4": {
56+
"description": "After deleting list",
57+
"start": "vram_start",
58+
"size": "vram_16_size",
59+
"expected_CRCs": [
60+
"472EC618"
61+
]
62+
},
63+
"5": {
64+
"description": "Test program exit",
65+
"start": "vram_start",
66+
"size": "vram_16_size",
67+
"expected_CRCs": [
68+
"FFAF89BA",
69+
"101734A5",
70+
"9DA19F44",
71+
"A32840C8",
72+
"349F4775"
73+
]
74+
}
75+
}
76+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# ----------------------------
2+
# Makefile Options
3+
# ----------------------------
4+
5+
NAME = DEMO
6+
ICON = icon.png
7+
DESCRIPTION = "CE C Toolchain Demo"
8+
COMPRESSED = NO
9+
10+
CFLAGS = -Wall -Wextra -Oz
11+
CXXFLAGS = -Wall -Wextra -Oz
12+
13+
# ----------------------------
14+
15+
include $(shell cedev-config --makefile)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
### Var management Demo
2+
3+
This demo demonstrates using some OS routines for variable management.
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#include <assert.h>
2+
#include <stdbool.h>
3+
#include <stdint.h>
4+
#include <string.h>
5+
6+
#include <ti/getcsc.h>
7+
#include <ti/screen.h>
8+
#include <ti/vars.h>
9+
#include <debug.h>
10+
11+
#define MY_LIST_NAME "\x5DTESTL"
12+
13+
struct Counters
14+
{
15+
unsigned int ram;
16+
unsigned int flash;
17+
};
18+
19+
// Those can't be deleted.
20+
static bool isInternalVar(uint8_t varType, const char* name)
21+
{
22+
return !strcmp(name, "#")
23+
|| (varType == OS_TYPE_EQU && !strcmp(name, "."))
24+
|| (varType == OS_TYPE_PRGM && !strcmp(name, "!"));
25+
}
26+
27+
// Walk through the VAT, debug-prints some info about the entries, and returns the number of entries seen
28+
static struct Counters walkVAT(void)
29+
{
30+
void* vatStart = os_GetSymTablePtr();
31+
void* nextEntry = NULL;
32+
void* entry = vatStart;
33+
uint24_t varType = 0, nameLen = 0;
34+
char name[9] = {0};
35+
void* data = NULL;
36+
struct Counters counters = { 0, 0 };
37+
38+
while (entry)
39+
{
40+
nextEntry = os_NextSymEntry(entry, &varType, &nameLen, name, &data);
41+
42+
const bool isArchived = (uintptr_t)data < (uintptr_t)os_RamStart;
43+
const bool isNamed = entry <= *(void**)0xD0259D; // progPtr
44+
const bool isInternal = isInternalVar(varType, name);
45+
const uint8_t* actualDataAddr = isArchived ? (data + 9 + isNamed + nameLen) : data;
46+
47+
if (isArchived) {
48+
counters.flash++;
49+
} else {
50+
counters.ram++;
51+
}
52+
53+
dbg_printf("%s%s entry %p (data @ %06X ; actual data @ %06X) : [type %02X] [namelen %d] \"%s\"\n",
54+
isArchived ? "Archived" : "RAM", isInternal ? " internal" : "", entry, (uintptr_t)data,
55+
(uintptr_t)actualDataAddr, varType, nameLen, name);
56+
57+
entry = nextEntry;
58+
}
59+
60+
return counters;
61+
}
62+
63+
int main(void)
64+
{
65+
static char buf[31] = {0};
66+
67+
os_ClrHome();
68+
69+
struct Counters countersBefore = walkVAT();
70+
dbg_printf("before: %d R / %d F", countersBefore.ram, countersBefore.flash);
71+
os_PutStrFull("Before creating list");
72+
os_NewLine();
73+
os_NewLine();
74+
while (!os_GetCSC());
75+
76+
int ret = 0;
77+
ret = os_SetListDim(MY_LIST_NAME, 10);
78+
dbg_printf("os_SetListDim ret = %d\n", ret);
79+
assert(ret == 0);
80+
os_PutStrFull("Created. ");
81+
82+
void *entry, *data;
83+
ret = os_ChkFindSym(OS_TYPE_REAL_LIST, MY_LIST_NAME, &entry, &data);
84+
dbg_printf("os_ChkFindSym ret = %d. entry = %p, data = %p\n", ret, entry, data);
85+
assert(ret == 1);
86+
87+
struct Counters countersAfter = walkVAT();
88+
dbg_printf("created: %d R / %d F", countersAfter.ram, countersAfter.flash);
89+
snprintf(buf, 30, "Diff %dR %dF", countersAfter.ram - countersBefore.ram, countersAfter.flash - countersBefore.flash);
90+
os_PutStrFull(buf);
91+
os_NewLine();
92+
while (!os_GetCSC());
93+
94+
bool archived = arcUnarcVariable(OS_TYPE_REAL_LIST, sizeof(MY_LIST_NAME)-1, MY_LIST_NAME);
95+
assert(archived);
96+
os_PutStrFull("Archived. ");
97+
98+
struct Counters countersArchived = walkVAT();
99+
dbg_printf("archived: %d R / %d F", countersArchived.ram, countersArchived.flash);
100+
snprintf(buf, 30, "Diff %dR %dF", countersArchived.ram - countersAfter.ram, countersArchived.flash - countersAfter.flash);
101+
os_PutStrFull(buf);
102+
os_NewLine();
103+
while (!os_GetCSC());
104+
105+
ret = os_ChkFindSym(OS_TYPE_REAL_LIST, MY_LIST_NAME, &entry, &data);
106+
dbg_printf("os_ChkFindSym ret = %d. entry = %p, data = %p\n", ret, entry, data);
107+
assert(ret == 1);
108+
109+
os_DelVar(entry);
110+
111+
ret = os_ChkFindSym(OS_TYPE_REAL_LIST, MY_LIST_NAME, &entry, &data);
112+
dbg_printf("os_ChkFindSym ret = %d. entry = %p, data = %p\n", ret, entry, data);
113+
assert(ret == 0);
114+
os_PutStrFull("Deleted. ");
115+
116+
struct Counters countersDeleted = walkVAT();
117+
dbg_printf("deleted: %d R / %d F", countersDeleted.ram, countersDeleted.flash);
118+
snprintf(buf, 30, "Diff %dR %dF", countersDeleted.ram - countersArchived.ram, countersDeleted.flash - countersArchived.flash);
119+
os_PutStrFull(buf);
120+
121+
while (!os_GetCSC());
122+
return 0;
123+
}

0 commit comments

Comments
 (0)