Skip to content

Commit f84a1aa

Browse files
committed
tests: add standalone var management tests.
1 parent 28de691 commit f84a1aa

File tree

5 files changed

+176
-0
lines changed

5 files changed

+176
-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,40 @@
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|500",
16+
"hashWait|2"
17+
],
18+
"hashes": {
19+
"1": {
20+
"description": "List variable handled",
21+
"start": "vram_start",
22+
"size": "vram_16_size",
23+
"expected_CRCs": [
24+
"BDBF7F60"
25+
]
26+
},
27+
"2": {
28+
"description": "Test program exit",
29+
"start": "vram_start",
30+
"size": "vram_16_size",
31+
"expected_CRCs": [
32+
"FFAF89BA",
33+
"101734A5",
34+
"9DA19F44",
35+
"A32840C8",
36+
"349F4775"
37+
]
38+
}
39+
}
40+
}
+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,110 @@
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+
struct Counters {
12+
unsigned int ram;
13+
unsigned int flash;
14+
};
15+
16+
// Those can't be deleted.
17+
static bool isInternalVar(uint8_t varType, const char* name) {
18+
return !strcmp(name, "#")
19+
|| (varType == OS_TYPE_EQU && !strcmp(name, "."))
20+
|| (varType == OS_TYPE_PRGM && !strcmp(name, "!"));
21+
}
22+
23+
// Walk through the VAT, debug-prints some info about the entries, and returns the number of entries seen
24+
static struct Counters walkVAT(void)
25+
{
26+
void* vatStart = os_GetSymTablePtr();
27+
void* nextEntry = NULL;
28+
void* entry = vatStart;
29+
uint24_t varType = 0, nameLen = 0;
30+
char name[9] = {0};
31+
void* data = NULL;
32+
struct Counters counters = { 0, 0 };
33+
34+
while (entry)
35+
{
36+
nextEntry = os_NextSymEntry(entry, &varType, &nameLen, name, &data);
37+
38+
const bool isArchived = (uintptr_t)data < (uintptr_t)os_RamStart;
39+
const bool isNamed = entry <= *(void**)0xD0259D; // progPtr
40+
const bool isInternal = isInternalVar(varType, name);
41+
const uint8_t* actualDataAddr = isArchived ? (data + 9 + isNamed + nameLen) : data;
42+
43+
if (isArchived) {
44+
counters.flash++;
45+
} else {
46+
counters.ram++;
47+
}
48+
49+
dbg_printf("%s%s entry %p (data @ %06X ; actual data @ %06X) : [type %02X] [namelen %d] \"%s\"\n",
50+
isArchived ? "Archived" : "RAM", isInternal ? " internal" : "", entry, (uintptr_t)data,
51+
(uintptr_t)actualDataAddr, varType, nameLen, name);
52+
53+
entry = nextEntry;
54+
}
55+
56+
return counters;
57+
}
58+
59+
int main(void)
60+
{
61+
char buf[31] = {0};
62+
struct Counters counters = { 0, 0 };
63+
64+
os_ClrHome();
65+
66+
counters = walkVAT();
67+
snprintf(buf, 30, "before: %d R / %d F", counters.ram, counters.flash);
68+
os_PutStrFull(buf);
69+
os_NewLine();
70+
71+
int ret = 0;
72+
ret = os_SetListDim("\x5DTESTL", 10);
73+
dbg_printf("os_SetListDim ret = %d\n", ret);
74+
assert(ret == 0);
75+
76+
void *entry, *data;
77+
ret = os_ChkFindSym(OS_TYPE_REAL_LIST, "\x5DTESTL", &entry, &data);
78+
dbg_printf("os_ChkFindSym ret = %d. entry = %p, data = %p\n", ret, entry, data);
79+
assert(ret == 1);
80+
81+
counters = walkVAT();
82+
snprintf(buf, 30, "created: %d R / %d F", counters.ram, counters.flash);
83+
os_PutStrFull(buf);
84+
os_NewLine();
85+
86+
bool archived = arcUnarcVariable(OS_TYPE_REAL_LIST, 6, "\x5DTESTL");
87+
assert(archived);
88+
89+
counters = walkVAT();
90+
snprintf(buf, 30, "archived: %d R / %d F", counters.ram, counters.flash);
91+
os_PutStrFull(buf);
92+
os_NewLine();
93+
94+
ret = os_ChkFindSym(OS_TYPE_REAL_LIST, "\x5DTESTL", &entry, &data);
95+
dbg_printf("os_ChkFindSym ret = %d. entry = %p, data = %p\n", ret, entry, data);
96+
assert(ret == 1);
97+
98+
os_DelVar(entry);
99+
100+
ret = os_ChkFindSym(OS_TYPE_REAL_LIST, "\x5DTESTL", &entry, &data);
101+
dbg_printf("os_ChkFindSym ret = %d. entry = %p, data = %p\n", ret, entry, data);
102+
assert(ret == 0);
103+
104+
counters = walkVAT();
105+
snprintf(buf, 30, "removed: %d R / %d F", counters.ram, counters.flash);
106+
os_PutStrFull(buf);
107+
108+
while (!os_GetCSC());
109+
return 0;
110+
}

0 commit comments

Comments
 (0)