Skip to content

Commit 8cf39d8

Browse files
authored
Merge pull request #164 from ecubus/test_log_opt
Test log opt
2 parents 2a8d089 + f8f37d8 commit 8cf39d8

File tree

10 files changed

+101
-43
lines changed

10 files changed

+101
-43
lines changed

resources/lib/js/sa.node

1 KB
Binary file not shown.

resources/lib/js/uds.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/lib/js/uds.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/ipc/uds.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,9 @@ ipcMain.handle('ipc-run-test', async (event, ...arg) => {
153153
last.close()
154154
testMap.delete(test.id)
155155
}
156-
const nodeItem: NodeItem = {
157-
id: test.id,
158-
name: test.name,
159-
channel: test.channel,
160-
script: test.script
161-
}
156+
162157
const node = new NodeClass(
163-
nodeItem,
158+
test,
164159
canBaseMap,
165160
linBaseMap,
166161
doips,

src/main/nodeItem.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,10 @@ export class NodeClass {
182182
const tp = new CAN_TP(canBaseItem)
183183
for (const [index, addr] of tester.address.entries()) {
184184
if (addr.type == 'can' && addr.canAddr) {
185-
const idT = tp.getReadId(addr.canAddr, tester.simulateBy != nodeItem.id)
185+
const idT = tp.getReadId(
186+
addr.canAddr,
187+
nodeItem.isTest ? true : tester.simulateBy != nodeItem.id
188+
)
186189
tp.event.on(idT, (data) => {
187190
if (data instanceof CanTpError) {
188191
//TODO:
@@ -205,7 +208,10 @@ export class NodeClass {
205208
}
206209
})
207210
if (index == 0) {
208-
const idR = tp.getReadId(swapAddr(addr.canAddr), true)
211+
const idR = tp.getReadId(
212+
swapAddr(addr.canAddr),
213+
nodeItem.isTest ? tester.simulateBy != nodeItem.id : true
214+
)
209215
tp.event.on(idR, (data) => {
210216
if (data instanceof CanTpError) {
211217
//TODO:
@@ -287,7 +293,7 @@ export class NodeClass {
287293
if (ethBaseItem && tester.type == 'eth') {
288294
const baseItem = this.doips.find((d) => d.base.id == ethBaseItem.id)
289295
if (baseItem) {
290-
if (tester.simulateBy == nodeItem.id) {
296+
if (tester.simulateBy == nodeItem.id && !nodeItem.isTest) {
291297
baseItem.registerEntity(true, this.log)
292298
}
293299
for (const addr of tester.address) {

src/main/share/uds.d.ts.html

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { dot } from 'node:test/reporters';
22
export { default as assert } from 'node:assert';
3-
import { describe } from 'node:test';
4-
export { after, afterEach, before, beforeEach, test } from 'node:test';
3+
import { test as test$1 } from 'node:test';
4+
export { after, afterEach, before, beforeEach } from 'node:test';
55

66
/**
77
* Represents a CAN (Controller Area Network) message.
@@ -402,7 +402,30 @@
402402
private loadDll;
403403
}
404404

405-
declare const selfDescribe: typeof describe;
405+
/**
406+
* Test function for writing test cases. Provides test context and logging.
407+
*
408+
* @category TEST
409+
* @param {string} name - The name of the test case
410+
* @param {Function} fn - The test function to execute
411+
*
412+
* @example
413+
* ```ts
414+
* // Basic test case
415+
* test('should add numbers correctly', () => {
416+
* assert.equal(1 + 1, 2);
417+
* });
418+
*
419+
* // Async test case
420+
* test('should handle async operations', async () => {
421+
* const result = await someAsyncFunction();
422+
* assert.equal(result, expectedValue);
423+
* });
424+
* ```
425+
*/
426+
declare function test(name: string, fn: () => void | Promise<void>): void;
427+
428+
declare const selfDescribe: typeof test$1.describe.only;
406429

407430
declare const testerList: readonly [
408431
{{#each this.testers}}
@@ -1529,4 +1552,4 @@
15291552
*/
15301553
declare function linStopScheduler(device?: string): Promise<void>;
15311554

1532-
export { CAN_ADDR_FORMAT, CAN_ADDR_TYPE, CAN_ID_TYPE, type CanAddr, type CanMessage, type CanMsgType, DiagJob, DiagRequest, DiagResponse, type EntityAddr, type EthAddr, type JobName, type LinAddr, LinChecksumType, LinDirection, LinMode, type LinMsg, RegisterEthVirtualEntity, SecureAccessDll, type ServiceEvent, type ServiceId, type ServiceItem, type ServiceName, type ServiceNameRecv, type ServiceNameSend, type SignalName, type TesterInfo, type TesterName, type UdsAddress, type UdsSeqName, Util, UtilClass, type VariableMap, selfDescribe as describe, linStartScheduler, linStopScheduler, output, reporter, runUdsSeq, setSignal, setVar, stopUdsSeq };
1555+
export { CAN_ADDR_FORMAT, CAN_ADDR_TYPE, CAN_ID_TYPE, type CanAddr, type CanMessage, type CanMsgType, DiagJob, DiagRequest, DiagResponse, type EntityAddr, type EthAddr, type JobName, type LinAddr, LinChecksumType, LinDirection, LinMode, type LinMsg, RegisterEthVirtualEntity, SecureAccessDll, type ServiceEvent, type ServiceId, type ServiceItem, type ServiceName, type ServiceNameRecv, type ServiceNameSend, type SignalName, type TesterInfo, type TesterName, type UdsAddress, type UdsSeqName, Util, UtilClass, type VariableMap, selfDescribe as describe, linStartScheduler, linStopScheduler, output, reporter, runUdsSeq, setSignal, setVar, stopUdsSeq, test };

src/main/worker/uds.ts

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,35 +40,50 @@ export type { CanMsgType } from '../share/can'
4040
export type { UdsAddress }
4141
import { dot } from 'node:test/reporters'
4242
import assert from 'node:assert'
43-
/**
44-
* @category TEST
45-
*/
46-
export { assert }
47-
48-
/**
49-
* @category TEST
50-
*/
51-
export { test } from 'node:test'
52-
53-
/**
54-
* @category TEST
55-
*/
56-
export { beforeEach } from 'node:test'
5743

5844
/**
5945
* @category TEST
6046
*/
61-
export { afterEach } from 'node:test'
47+
export { assert }
6248

49+
import { test as nodeTest } from 'node:test'
6350
/**
51+
* Test function for writing test cases. Provides test context and logging.
52+
*
6453
* @category TEST
54+
* @param {string} name - The name of the test case
55+
* @param {Function} fn - The test function to execute
56+
*
57+
* @example
58+
* ```ts
59+
* // Basic test case
60+
* test('should add numbers correctly', () => {
61+
* assert.equal(1 + 1, 2);
62+
* });
63+
*
64+
* // Async test case
65+
* test('should handle async operations', async () => {
66+
* const result = await someAsyncFunction();
67+
* assert.equal(result, expectedValue);
68+
* });
69+
* ```
6570
*/
66-
export { before } from 'node:test'
71+
export function test(name: string, fn: () => void | Promise<void>) {
72+
nodeTest(name, (t) => {
73+
t.before(() => {
74+
console.log(`<<< TEST START ${name}>>>`)
75+
})
76+
t.after(() => {
77+
console.log(`<<< TEST END ${name}>>>`)
78+
})
79+
return fn()
80+
})
81+
}
6782

6883
/**
6984
* @category TEST
7085
*/
71-
export { after } from 'node:test'
86+
export { beforeEach, afterEach, before, after } from 'node:test'
7287

7388
/**
7489
* @category TEST

src/main/workerClient.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,29 @@ export default class UdsTester {
164164

165165
d.worker.stdout.on('data', (data: any) => {
166166
if (!this.selfStop) {
167-
const str = data.toString().trim()
168-
if (str) {
169-
this.log.scriptMsg(str, this.ts)
167+
if (this.env.MODE == 'test') {
168+
const testStartRegex = /^<<< TEST START .+>>>$/
169+
const testEndRegex = /^<<< TEST END .+>>>$/
170+
const str = data.toString().trim()
171+
if (testStartRegex.test(str) || testEndRegex.test(str)) {
172+
return
173+
}
170174
}
175+
this.log.scriptMsg(data.toString(), this.ts)
171176
}
172177
})
173178

174179
d.worker.stderr.on('data', (data: any) => {
175180
if (!this.selfStop) {
176-
const str = data.toString().trim()
177-
if (str) {
178-
this.log.systemMsg(str, this.ts, 'error')
181+
if (this.env.MODE == 'test') {
182+
const testStartRegex = /^<<< TEST START .+>>>$/
183+
const testEndRegex = /^<<< TEST END .+>>>$/
184+
const str = data.toString().trim()
185+
if (testStartRegex.test(str) || testEndRegex.test(str)) {
186+
return
187+
}
179188
}
189+
this.log.systemMsg(data.toString(), this.ts, 'error')
180190
}
181191
})
182192

src/renderer/src/views/uds/log.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
:icon="successIcon"
2929
style="font-size: 14px; margin-top: 8px"
3030
/>
31+
<Icon
32+
v-else-if="row.level == 'primary'"
33+
:icon="primaryIcon"
34+
style="font-size: 14px; margin-top: 8px"
35+
/>
3136
</template>
3237
<template #toolbar>
3338
<div
@@ -79,6 +84,7 @@ import errorIcon from '@iconify/icons-material-symbols/chat-error-outline-sharp'
7984
import warnIcon from '@iconify/icons-material-symbols/warning-outline-rounded'
8085
import saveIcon from '@iconify/icons-material-symbols/save'
8186
import successIcon from '@iconify/icons-material-symbols/check-circle-outline'
87+
import primaryIcon from '@iconify/icons-material-symbols/line-start-square-outline-rounded'
8288
import { useProjectStore } from '@r/stores/project'
8389
import type { TestEvent } from 'node:test/reporters'
8490
import { useGlobalStart } from '@r/stores/runtime'
@@ -283,8 +289,9 @@ function testLog(
283289
logData.push({
284290
time: new Date().toLocaleTimeString(),
285291
label: item.message.data.data.name,
286-
level: 'info',
292+
level: 'primary',
287293
message: `Test ${item.message.data.data.name} starting...`,
294+
288295
id: cnt++
289296
})
290297
} else if (item.message.data.type == 'test:pass') {
@@ -360,7 +367,9 @@ onUnmounted(() => {
360367
.info {
361368
color: var(--el-color-info-dark-5);
362369
}
363-
370+
.primary {
371+
color: var(--el-color-primary);
372+
}
364373
.debug {
365374
color: var(--el-color-info);
366375
}

src/renderer/src/views/uds/test.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@
191191
</el-tree>
192192
</el-scrollbar>
193193
</div>
194-
<div id="testerServiceShift" class="shift" />
194+
<div id="tttShift" class="shift" />
195195
<div class="right" :style="{ left: leftWidth + 5 + 'px' }">
196196
<trace-component
197197
ref="traceRef"
@@ -755,7 +755,7 @@ function testLog(
755755
}
756756
}
757757
onMounted(() => {
758-
window.jQuery('#testerServiceShift').resizable({
758+
window.jQuery('#tttShift').resizable({
759759
handles: 'e',
760760
resize: (e, ui) => {
761761
leftWidth.value = ui.size.width

0 commit comments

Comments
 (0)