未验证 提交 01f45a01 编写于 作者: O openharmony_ci 提交者: Gitee

!6275 hisyseventjs主干代码提交

Merge pull request !6275 from chenxuihui/master
...@@ -14,15 +14,6 @@ ...@@ -14,15 +14,6 @@
], ],
"type": "AppInstallKit", "type": "AppInstallKit",
"cleanup-apps": true "cleanup-apps": true
},
{
"type": "ShellKit",
"run-command": [
"setenforce 0"
],
"teardown-command": [
"setenforce 1"
]
} }
] ]
} }
\ No newline at end of file
...@@ -332,6 +332,7 @@ describe('hiSysEventJsTest', function () { ...@@ -332,6 +332,7 @@ describe('hiSysEventJsTest', function () {
rules: [{ rules: [{
domain: "RELIABILITY", domain: "RELIABILITY",
name: "STACK", name: "STACK",
tag: "STABILITY",
ruleType: hiSysEvent.RuleType.PREFIX ruleType: hiSysEvent.RuleType.PREFIX
}], }],
onEvent: (info) => { onEvent: (info) => {
...@@ -349,10 +350,18 @@ describe('hiSysEventJsTest', function () { ...@@ -349,10 +350,18 @@ describe('hiSysEventJsTest', function () {
console.info(`testHiSysEventApi12 Onservice died`); console.info(`testHiSysEventApi12 Onservice died`);
} }
} }
let result = hiSysEvent.addWatcher(watcher) try {
expect(result).assertEqual(0) hiSysEvent.addWatcher(watcher)
console.info('testHiSysEventApi12 end') expect(true).assertTrue()
done(); console.info('testHiSysEventApi12 end')
done();
} catch (err) {
console.error(`testHiSysEventApi12 > error code: ${err.code}, error msg: ${err.message}`)
expect(err.code == 201).assertTrue()
console.info('testHiSysEventApi12 end')
done()
}
hiSysEvent.removeWatcher(watcher)
}) })
/** /**
...@@ -383,10 +392,18 @@ describe('hiSysEventJsTest', function () { ...@@ -383,10 +392,18 @@ describe('hiSysEventJsTest', function () {
console.info(`testHiSysEventApi13 Onservice died`); console.info(`testHiSysEventApi13 Onservice died`);
} }
} }
let result = hiSysEvent.addWatcher(watcher) try {
expect(result).assertEqual(0) hiSysEvent.addWatcher(watcher)
console.info('testHiSysEventApi13 end') expect(true).assertTrue()
done(); console.info('testHiSysEventApi13 end')
done();
} catch (err) {
console.error(`testHiSysEventApi13 > error code: ${err.code}, error msg: ${err.message}`)
expect(err.code == 201).assertTrue()
console.info('testHiSysEventApi13 end')
done()
}
hiSysEvent.removeWatcher(watcher)
}) })
/** /**
...@@ -417,10 +434,18 @@ describe('hiSysEventJsTest', function () { ...@@ -417,10 +434,18 @@ describe('hiSysEventJsTest', function () {
console.info(`testHiSysEventApi14 Onservice died`); console.info(`testHiSysEventApi14 Onservice died`);
} }
} }
let result = hiSysEvent.addWatcher(watcher) try {
expect(result).assertEqual(0) hiSysEvent.addWatcher(watcher)
console.info('testHiSysEventApi14 end') expect(true).assertTrue()
done(); console.info('testHiSysEventApi14 end')
done();
} catch (err) {
console.error(`testHiSysEventApi14 > error code: ${err.code}, error msg: ${err.message}`)
expect(err.code == 201)
console.info('testHiSysEventApi14 end')
done()
}
hiSysEvent.removeWatcher(watcher)
}) })
/** /**
...@@ -452,10 +477,18 @@ describe('hiSysEventJsTest', function () { ...@@ -452,10 +477,18 @@ describe('hiSysEventJsTest', function () {
console.info(`testHiSysEventApi15 Onservice died`); console.info(`testHiSysEventApi15 Onservice died`);
} }
} }
let result = hiSysEvent.addWatcher(watcher) try {
expect(result).assertEqual(0) hiSysEvent.addWatcher(watcher)
console.info('testHiSysEventApi15 end') expect(true).assertTrue()
done(); console.info('testHiSysEventApi15 end')
done();
} catch (err) {
console.error(`testHiSysEventApi15 > error code: ${err.code}, error msg: ${err.message}`)
expect(err.code == 201).assertTrue()
console.info('testHiSysEventApi15 end')
done()
}
hiSysEvent.removeWatcher(watcher)
}) })
/** /**
...@@ -487,10 +520,18 @@ describe('hiSysEventJsTest', function () { ...@@ -487,10 +520,18 @@ describe('hiSysEventJsTest', function () {
console.info(`testHiSysEventApi16 Onservice died`); console.info(`testHiSysEventApi16 Onservice died`);
} }
} }
let result = hiSysEvent.addWatcher(watcher) try {
expect(result).assertEqual(0) hiSysEvent.addWatcher(watcher)
console.info('testHiSysEventApi16 end') expect(true).assertTrue()
done(); console.info('testHiSysEventApi16 end')
done();
} catch (err) {
console.error(`testHiSysEventApi16 > error code: ${err.code}, error msg: ${err.message}`)
expect(err.code == 201).assertTrue()
console.info('testHiSysEventApi16 end')
done()
}
hiSysEvent.removeWatcher(watcher)
}) })
/** /**
...@@ -522,10 +563,18 @@ describe('hiSysEventJsTest', function () { ...@@ -522,10 +563,18 @@ describe('hiSysEventJsTest', function () {
console.info(`testHiSysEventApi17 Onservice died`); console.info(`testHiSysEventApi17 Onservice died`);
} }
} }
let result = hiSysEvent.addWatcher(watcher) try {
expect(result).assertEqual(0) hiSysEvent.addWatcher(watcher)
console.info('testHiSysEventApi17 end') expect(true).assertTrue()
done(); console.info('testHiSysEventApi17 end')
done();
} catch (err) {
console.error(`testHiSysEventApi17 > error code: ${err.code}, error msg: ${err.message}`)
expect(err.code == 201).assertTrue()
console.info('testHiSysEventApi17 end')
done()
}
hiSysEvent.removeWatcher(watcher)
}) })
/** /**
...@@ -556,15 +605,20 @@ describe('hiSysEventJsTest', function () { ...@@ -556,15 +605,20 @@ describe('hiSysEventJsTest', function () {
console.info(`testHiSysEventApi18 Onservice died`); console.info(`testHiSysEventApi18 Onservice died`);
} }
} }
let result = hiSysEvent.addWatcher(watcher) hiSysEvent.addWatcher(watcher)
expect(result).assertEqual(0)
setTimeout(() => { setTimeout(() => {
result = hiSysEvent.removeWatcher(watcher) try {
expect(result).assertEqual(0) hiSysEvent.removeWatcher(watcher)
done() expect(true).assertTrue()
console.info('testHiSysEventApi18 end') console.info('testHiSysEventApi18 end')
done();
} catch (err) {
console.error(`testHiSysEventApi18 > error code: ${err.code}, error msg: ${err.message}`)
expect(err.code == 201).assertTrue()
console.info('testHiSysEventApi18 end')
done()
}
}, 1000) }, 1000)
done();
}) })
/** /**
...@@ -595,15 +649,20 @@ describe('hiSysEventJsTest', function () { ...@@ -595,15 +649,20 @@ describe('hiSysEventJsTest', function () {
console.info(`testHiSysEventApi19 Onservice died`); console.info(`testHiSysEventApi19 Onservice died`);
} }
} }
let result = hiSysEvent.addWatcher(watcher) hiSysEvent.addWatcher(watcher)
expect(result).assertEqual(0)
setTimeout(() => { setTimeout(() => {
result = hiSysEvent.removeWatcher(watcher) try {
expect(result).assertEqual(0) hiSysEvent.removeWatcher(watcher)
done() expect(true).assertTrue()
console.info('testHiSysEventApi19 end') console.info('testHiSysEventApi19 end')
done();
} catch (err) {
console.error(`testHiSysEventApi19 > error code: ${err.code}, error msg: ${err.message}`)
expect(err.code == 201).assertTrue()
console.info('testHiSysEventApi19 end')
done()
}
}, 1000) }, 1000)
done();
}) })
/** /**
...@@ -634,15 +693,20 @@ describe('hiSysEventJsTest', function () { ...@@ -634,15 +693,20 @@ describe('hiSysEventJsTest', function () {
console.info(`testHiSysEventApi20 Onservice died`); console.info(`testHiSysEventApi20 Onservice died`);
} }
} }
let result = hiSysEvent.addWatcher(watcher) hiSysEvent.addWatcher(watcher)
expect(result).assertEqual(0)
setTimeout(() => { setTimeout(() => {
result = hiSysEvent.removeWatcher(watcher) try {
expect(result).assertEqual(0) hiSysEvent.removeWatcher(watcher)
done() expect(true).assertTrue()
console.info('testHiSysEventApi20 end') console.info('testHiSysEventApi20 end')
done();
} catch (err) {
console.error(`testHiSysEventApi20 > error code: ${err.code}, error msg: ${err.message}`)
expect(err.code == 201).assertTrue()
console.info('testHiSysEventApi20 end')
done()
}
}, 1000) }, 1000)
done();
}) })
/** /**
...@@ -674,15 +738,20 @@ describe('hiSysEventJsTest', function () { ...@@ -674,15 +738,20 @@ describe('hiSysEventJsTest', function () {
console.info(`testHiSysEventApi21 Onservice died`); console.info(`testHiSysEventApi21 Onservice died`);
} }
} }
let result = hiSysEvent.addWatcher(watcher) hiSysEvent.addWatcher(watcher)
expect(result).assertEqual(0)
setTimeout(() => { setTimeout(() => {
result = hiSysEvent.removeWatcher(watcher) try {
expect(result).assertEqual(0) hiSysEvent.removeWatcher(watcher)
done() expect(true).assertTrue()
console.info('testHiSysEventApi21 end') console.info('testHiSysEventApi21 end')
done();
} catch (err) {
console.error(`testHiSysEventApi21 > error code: ${err.code}, error msg: ${err.message}`)
expect(err.code == 201).assertTrue()
console.info('testHiSysEventApi21 end')
done()
}
}, 1000) }, 1000)
done();
}) })
/** /**
...@@ -714,15 +783,20 @@ describe('hiSysEventJsTest', function () { ...@@ -714,15 +783,20 @@ describe('hiSysEventJsTest', function () {
console.info(`testHiSysEventApi22 Onservice died`); console.info(`testHiSysEventApi22 Onservice died`);
} }
} }
let result = hiSysEvent.addWatcher(watcher) hiSysEvent.addWatcher(watcher)
expect(result).assertEqual(0)
setTimeout(() => { setTimeout(() => {
result = hiSysEvent.removeWatcher(watcher) try {
expect(result).assertEqual(0) hiSysEvent.removeWatcher(watcher)
done() expect(true).assertTrue()
console.info('testHiSysEventApi22 end') console.info('testHiSysEventApi22 end')
done();
} catch (err) {
console.error(`testHiSysEventApi22 > error code: ${err.code}, error msg: ${err.message}`)
expect(err.code == 201).assertTrue()
console.info('testHiSysEventApi22 end')
done()
}
}, 1000) }, 1000)
done();
}) })
/** /**
...@@ -754,15 +828,20 @@ describe('hiSysEventJsTest', function () { ...@@ -754,15 +828,20 @@ describe('hiSysEventJsTest', function () {
console.info(`testHiSysEventApi23 Onservice died`); console.info(`testHiSysEventApi23 Onservice died`);
} }
} }
let result = hiSysEvent.addWatcher(watcher) hiSysEvent.addWatcher(watcher)
expect(result).assertEqual(0)
setTimeout(() => { setTimeout(() => {
result = hiSysEvent.removeWatcher(watcher) try {
expect(result).assertEqual(0) hiSysEvent.removeWatcher(watcher)
done() expect(true).assertTrue()
console.info('testHiSysEventApi23 end') console.info('testHiSysEventApi23 end')
done();
} catch (err) {
console.error(`testHiSysEventApi23 > error code: ${err.code}, error msg: ${err.message}`)
expect(err.code == 201).assertTrue()
console.info('testHiSysEventApi23 end')
done()
}
}, 1000) }, 1000)
done();
}) })
/** /**
...@@ -772,69 +851,72 @@ describe('hiSysEventJsTest', function () { ...@@ -772,69 +851,72 @@ describe('hiSysEventJsTest', function () {
*/ */
it('testHiSysEventApi24', 1, async function (done) { it('testHiSysEventApi24', 1, async function (done) {
console.info('testHiSysEventApi24 start') console.info('testHiSysEventApi24 start')
hiSysEvent.write({ try {
domain: "ACCOUNT", hiSysEvent.write({
name: "PERMISSION_EXCEPTION", domain: "ACCOUNT",
eventType: hiSysEvent.EventType.SECURITY, name: "PERMISSION_EXCEPTION",
params: { eventType: hiSysEvent.EventType.SECURITY,
PID: 487, params: {
UID: 103, PID: 487,
PACKAGE_NAME: "com.ohos.hisysevent.test", UID: 103,
PROCESS_NAME: "syseventservice", PACKAGE_NAME: "com.ohos.hisysevent.test",
MSG: "no msg." PROCESS_NAME: "syseventservice",
} MSG: "no msg."
},(err, value) => { }
console.log('testHiSysEventApi24 into json-callback'); },(err, value) => {
if (err) { console.log('testHiSysEventApi24 into json-callback');
console.error('in testHiSysEventApi24 test callback: err.code = ' + err.code) if (err) {
result = err.code console.error('in testHiSysEventApi24 test callback: err.code = ' + err.code)
} else { result = err.code
console.info('in testHiSysEventApi24 test callback: result = ' + value) } else {
result = value; console.info('in testHiSysEventApi24 test callback: result = ' + value)
} result = value;
}); }
setTimeout(() => { });
let ret = hiSysEvent.query({ setTimeout(() => {
beginTime: -1, hiSysEvent.query({
endTime: -1, beginTime: -1,
maxEvents: 1, endTime: -1,
}, [{ maxEvents: 1,
domain: "ACCOUNT", }, [{
names: ["PERMISSION_EXCEPTION"], domain: "ACCOUNT",
}], { names: ["PERMISSION_EXCEPTION"],
onQuery: function (infos, seqs) { }], {
console.info(`testHiSysEventApi24: onQuery...`) onQuery: function (infos, seqs) {
expect(infos.length >= 0).assertTrue() console.info(`testHiSysEventApi24: onQuery...`)
expect(seqs.length >= 0).assertTrue() expect(infos.length >= 0).assertTrue()
console.info(`testHiSysEventApi24: infos.size is ${infos.length}, seqs.length is ${seqs.length}`) expect(seqs.length >= 0).assertTrue()
if (infos instanceof Array) { console.info(`testHiSysEventApi24: infos.size is ${infos.length}, seqs.length is ${seqs.length}`)
for (let i = 0; i < infos.length; i++) { if (infos instanceof Array) {
let item = infos[i]; for (let i = 0; i < infos.length; i++) {
console.info(`testHiSysEventApi24: domain is ${item.domain}, name is ${item.name}, let item = infos[i];
eventType is ${item.eventType}`) console.info(`testHiSysEventApi24: domain is ${item.domain}, name is ${item.name},
if (item.params instanceof Object) { eventType is ${item.eventType}`)
for (const key in item.params) { if (item.params instanceof Object) {
console.info(`testHiSysEventApi24: ${key}: ${item.params[key]}`) for (const key in item.params) {
} console.info(`testHiSysEventApi24: ${key}: ${item.params[key]}`)
} }
} }
} }
if (seqs instanceof Array) { }
for (let i = 0; i < seqs.length; i++) { if (seqs instanceof Array) {
let item = seqs[i]; for (let i = 0; i < seqs.length; i++) {
console.info(`testHiSysEventApi24: seq${i}: ${item}`) let item = seqs[i];
} console.info(`testHiSysEventApi24: seq${i}: ${item}`)
} }
}, }
onComplete: function(reason, total) { },
console.info(`testHiSysEventApi24: onComplete...`) onComplete: function(reason, total) {
console.info(`testHiSysEventApi24: reason is ${reason}, total is ${total}`) console.info(`testHiSysEventApi24: onComplete...`)
done() console.info(`testHiSysEventApi24: reason is ${reason}, total is ${total}`)
console.info(`testHiSysEventApi24 end`) done()
} console.info(`testHiSysEventApi24 end`)
}) }
expect(ret).assertEqual(0) })
}, 1000); }, 1000);
} catch (error) {
console.error(`error code: ${error.code}, error msg: ${error.message}`);
}
}) })
/** /**
...@@ -844,25 +926,10 @@ describe('hiSysEventJsTest', function () { ...@@ -844,25 +926,10 @@ describe('hiSysEventJsTest', function () {
*/ */
it('testHiSysEventApi25', 1, async function (done) { it('testHiSysEventApi25', 1, async function (done) {
console.info('testHiSysEventApi25 start') console.info('testHiSysEventApi25 start')
hiSysEvent.write({ try {
domain: "HIVIEWDFX",
name: "SYS_USAGE",
eventType: hiSysEvent.EventType.STATISTIC,
},(err, value) => {
console.log('testHiSysEventApi25 into json-callback');
if (err) {
console.error('in testHiSysEventApi25 test callback: err.code = ' + err.code)
result = err.code
} else {
console.info('in testHiSysEventApi25 test callback: result = ' + value)
result = value;
}
});
console.info('add second..')
setTimeout(() => {
hiSysEvent.write({ hiSysEvent.write({
domain: "HIVIEWDFX", domain: "HIVIEWDFX",
name: "PLUGIN_STATS", name: "SYS_USAGE",
eventType: hiSysEvent.EventType.STATISTIC, eventType: hiSysEvent.EventType.STATISTIC,
},(err, value) => { },(err, value) => {
console.log('testHiSysEventApi25 into json-callback'); console.log('testHiSysEventApi25 into json-callback');
...@@ -873,50 +940,68 @@ describe('hiSysEventJsTest', function () { ...@@ -873,50 +940,68 @@ describe('hiSysEventJsTest', function () {
console.info('in testHiSysEventApi25 test callback: result = ' + value) console.info('in testHiSysEventApi25 test callback: result = ' + value)
result = value; result = value;
} }
}) });
},1000) console.info('add second..')
setTimeout(() => { setTimeout(() => {
let ret = hiSysEvent.query({ hiSysEvent.write({
beginTime: -1, domain: "HIVIEWDFX",
endTime: -1, name: "PLUGIN_STATS",
maxEvents: 5, eventType: hiSysEvent.EventType.STATISTIC,
}, [{ },(err, value) => {
domain: "HIVIEWDFX", console.log('testHiSysEventApi25 into json-callback');
names: ["SYS_USAGE","PLUGIN_STATS"], if (err) {
}], { console.error('in testHiSysEventApi25 test callback: err.code = ' + err.code)
onQuery: function (infos, seqs) { result = err.code
console.info(`testHiSysEventApi25: onQuery...`) } else {
expect(infos.length >= 0).assertTrue() console.info('in testHiSysEventApi25 test callback: result = ' + value)
expect(seqs.length >= 0).assertTrue() result = value;
console.info(`testHiSysEventApi25: infos.size is ${infos.length}, seqs.length is ${seqs.length}`) }
if (infos instanceof Array) { })
for (let i = 0; i < infos.length; i++) { },1000)
let item = infos[i]; setTimeout(() => {
console.info(`testHiSysEventApi25: domain is ${item.domain}, name is ${item.name}, hiSysEvent.query({
eventType is ${item.eventType}`) beginTime: -1,
if (item.params instanceof Object) { endTime: -1,
for (const key in item.params) { maxEvents: 5,
console.info(`testHiSysEventApi25: ${key}: ${item.params[key]}`) }, [{
} domain: "HIVIEWDFX",
} names: ["SYS_USAGE","PLUGIN_STATS"],
} }], {
} onQuery: function (infos, seqs) {
if (seqs instanceof Array) { console.info(`testHiSysEventApi25: onQuery...`)
for (let i = 0; i < seqs.length; i++) { expect(infos.length >= 0).assertTrue()
let item = seqs[i]; expect(seqs.length >= 0).assertTrue()
console.info(`testHiSysEventApi25: seq${i}: ${item}`) console.info(`testHiSysEventApi25: infos.size is ${infos.length}, seqs.length is ${seqs.length}`)
} if (infos instanceof Array) {
} for (let i = 0; i < infos.length; i++) {
}, let item = infos[i];
onComplete: function(reason, total) { console.info(`testHiSysEventApi25: domain is ${item.domain}, name is ${item.name},
console.info(`testHiSysEventApi25: onComplete...`) eventType is ${item.eventType}`)
console.info(`testHiSysEventApi25: reason is ${reason}, total is ${total}`) if (item.params instanceof Object) {
done() for (const key in item.params) {
console.info(`testHiSysEventApi25 end`) console.info(`testHiSysEventApi25: ${key}: ${item.params[key]}`)
} }
}) }
expect(ret).assertEqual(0) }
}, 1000); }
if (seqs instanceof Array) {
for (let i = 0; i < seqs.length; i++) {
let item = seqs[i];
console.info(`testHiSysEventApi25: seq${i}: ${item}`)
}
}
},
onComplete: function(reason, total) {
console.info(`testHiSysEventApi25: onComplete...`)
console.info(`testHiSysEventApi25: reason is ${reason}, total is ${total}`)
done()
console.info(`testHiSysEventApi25 end`)
}
})
}, 2000);
} catch (error) {
console.error(`error code: ${error.code}, error msg: ${error.message}`);
}
}) })
}) })
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册