From 4e311c19a7346f3d8d96c9de1667100512af6aa8 Mon Sep 17 00:00:00 2001 From: Ofek Shilon Date: Sat, 19 Jul 2025 20:53:07 +0300 Subject: [PATCH] Add Xtensa cfg test --- test/cfg-cases/cfg-xtensa.loop.json | 177 ++++++++++++++++++++++++++++ test/cfg-tests.ts | 16 +++ 2 files changed, 193 insertions(+) create mode 100644 test/cfg-cases/cfg-xtensa.loop.json diff --git a/test/cfg-cases/cfg-xtensa.loop.json b/test/cfg-cases/cfg-xtensa.loop.json new file mode 100644 index 000000000..eed500f5a --- /dev/null +++ b/test/cfg-cases/cfg-xtensa.loop.json @@ -0,0 +1,177 @@ +{ + "asm": [ + { + "text": "square(int, int*, int&):", + "source": null, + "labels": [] + }, + { + "text": " entry sp, 32", + "source": { + "file": null, + "line": 2, + "column": 37 + }, + "labels": [] + }, + { + "text": " blti a2, 1, .L1", + "source": { + "file": null, + "line": 3, + "column": 20 + }, + "labels": [ + { + "name": ".L1", + "range": { + "startCol": 24, + "endCol": 27 + } + } + ] + }, + { + "text": " slli a8, a2, 2", + "source": { + "file": null, + "line": 3, + "column": 20 + }, + "labels": [] + }, + { + "text": " addi a8, a8, -4", + "source": { + "file": null, + "line": 3, + "column": 20 + }, + "labels": [] + }, + { + "text": " srli a8, a8, 2", + "source": { + "file": null, + "line": 3, + "column": 20 + }, + "labels": [] + }, + { + "text": " addi.n a8, a8, 1", + "source": { + "file": null, + "line": 3, + "column": 20 + }, + "labels": [] + }, + { + "text": " loop a8, .L3_LEND", + "source": { + "file": null, + "line": 3, + "column": 20 + }, + "labels": [] + }, + { + "text": " l32i.n a2, a3, 0", + "source": { + "file": null, + "line": 4, + "column": 14 + }, + "labels": [] + }, + { + "text": " l32i.n a9, a4, 0", + "source": { + "file": null, + "line": 4, + "column": 14 + }, + "labels": [] + }, + { + "text": " add.n a2, a2, a9", + "source": { + "file": null, + "line": 4, + "column": 14 + }, + "labels": [] + }, + { + "text": " s32i.n a2, a3, 0", + "source": { + "file": null, + "line": 4, + "column": 14 + }, + "labels": [] + }, + { + "text": " addi.n a3, a3, 4", + "source": { + "file": null, + "line": 3, + "column": 20 + }, + "labels": [] + }, + { + "text": ".L1:", + "source": null, + "labels": [] + }, + { + "text": " retw.n", + "source": { + "file": null, + "line": 5, + "column": 1 + }, + "labels": [] + } + ], + "cfg": { + "square(int, int*, int&):": { + "nodes": [ + { + "id": "square(int, int*, int&):", + "label": "square(int, int*, int&):\n entry sp, 32\n blti a2, 1, .L1" + }, + { + "id": "square(int, int*, int&):@3", + "label": "square(int, int*, int&):@3\n slli a8, a2, 2\n addi a8, a8, -4\n srli a8, a8, 2\n addi.n a8, a8, 1\n loop a8, .L3_LEND\n l32i.n a2, a3, 0\n l32i.n a9, a4, 0\n add.n a2, a2, a9\n s32i.n a2, a3, 0\n addi.n a3, a3, 4" + }, + { + "id": ".L1:", + "label": ".L1:\n retw.n" + } + ], + "edges": [ + { + "from": "square(int, int*, int&):", + "to": ".L1:", + "arrows": "to", + "color": "green" + }, + { + "from": "square(int, int*, int&):", + "to": "square(int, int*, int&):@3", + "arrows": "to", + "color": "red" + }, + { + "from": "square(int, int*, int&):@3", + "to": ".L1:", + "arrows": "to", + "color": "grey" + } + ] + } + } +} \ No newline at end of file diff --git a/test/cfg-tests.ts b/test/cfg-tests.ts index 809994957..57bb35cf3 100644 --- a/test/cfg-tests.ts +++ b/test/cfg-tests.ts @@ -91,4 +91,20 @@ describe('Cfg test cases', () => { }); } }); + + describe('xtensa', () => { + // instructionSet is a real value, group/version/compilerType just need to be distinct from others + const xtensaCompilerInfo = makeFakeCompilerInfo({ + instructionSet: 'xtensa', + group: 'xtensa', + version: 'xtensa', + compilerType: 'xtensa', + }); + + for (const filename of files.filter(x => x.includes('xtensa'))) { + it(filename, async () => { + await DoCfgTest('python', path.join(testcasespath, filename), false, xtensaCompilerInfo); + }); + } + }); });