• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <ctype.h>
16 #include <unistd.h>
17 #include <time.h>
18 #include <stdlib.h>
19 
20 #include "init_param.h"
21 #include "modulemgr.h"
22 #include "init_module_engine.h"
23 #include "securec.h"
24 
25 #define MAX_COUNT 1000
26 #define TEST_CMD_NAME "param_randrom_write"
27 
28 #define READ_DURATION 100000
29 
30 static int g_testCmdIndex = 0;
PluginParamCmdWriteParam(int id,const char * name,int argc,const char ** argv)31 static int PluginParamCmdWriteParam(int id, const char *name, int argc, const char **argv)
32 {
33     if ((argv == NULL) || (argc < 1)) {
34         return -1;
35     }
36     int maxCount = MAX_COUNT;
37     if (argc > 1) {
38         maxCount = atoi(argv[1]);
39     }
40     (void)srand((unsigned)time(NULL));
41     char buffer[32] = { 0 }; // 32 buffer size
42     int count = 0;
43     while (count < maxCount) {
44         const int wait = READ_DURATION + READ_DURATION; // 100ms
45         int ret = sprintf_s(buffer, sizeof(buffer), "%d", count);
46         if (ret > 0) {
47             SystemWriteParam(argv[0], buffer);
48             usleep(wait);
49         }
50         count++;
51     }
52     return 0;
53 }
54 
MODULE_CONSTRUCTOR(void)55 MODULE_CONSTRUCTOR(void)
56 {
57     g_testCmdIndex = AddCmdExecutor(TEST_CMD_NAME, PluginParamCmdWriteParam);
58 }
59 
MODULE_DESTRUCTOR(void)60 MODULE_DESTRUCTOR(void)
61 {
62     RemoveCmdExecutor(TEST_CMD_NAME, g_testCmdIndex);
63 }
64