1 /*
2 * Copyright (c) 2022 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
16 #include <signal.h>
17 #include <stdlib.h>
18 #include <string.h>
19
20 #include "test.h"
21
22 unsigned short xsp0 = 0x330e;
23 unsigned short xsp1 = 0x5432;
24 unsigned short xsp2 = 0x9876;
25
handler(int sig)26 void handler(int sig)
27 {
28 exit(t_status);
29 }
30
31 /**
32 * @tc.name : seed48_0100
33 * @tc.desc : generate uniformly distributed pseudo-random numbers
34 * @tc.level : Level 0
35 */
seed48_0100(void)36 void seed48_0100(void)
37 {
38 long seed = 0x98765432;
39 srand48(seed);
40
41 unsigned short xs[] = {0x0001, 0x0012, 0x0123};
42 unsigned short *xsp = seed48(xs);
43 if (xsp[0] != xsp0 || xsp[1] != xsp1 || xsp[2] != xsp2) {
44 t_error("%s failed: xsp[0] = %x, xsp[1] = %x, xsp[2] = %x\n", __func__, xsp[0], xsp[1], xsp[2]);
45 }
46
47 memcpy(xs, xsp, sizeof(xs));
48 seed48(xs);
49 }
50
51 /**
52 * @tc.name : seed48_0200
53 * @tc.desc : generate uniformly distributed pseudo-random numbers with NULL
54 * @tc.level : Level 2
55 */
seed48_0200(void)56 void seed48_0200(void)
57 {
58 signal(SIGSEGV, handler);
59
60 seed48(NULL);
61 }
62
main(int argc,char * argv[])63 int main(int argc, char *argv[])
64 {
65 seed48_0100();
66 seed48_0200();
67
68 return t_status;
69 }
70