1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1996-1998 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #include <stddef.h>
28 #include <stdlib.h>
29 #include <sys/param.h>
30 #include <config_admin.h>
31 #include <memory.h>
32 #include "mema_test.h"
33 
34 extern mtest_func_t memory_test_normal;
35 extern mtest_func_t memory_test_quick;
36 extern mtest_func_t memory_test_extended;
37 
38 /*
39  * Default test is first entry in the table (MTEST_DEFAULT_TEST).
40  */
41 struct mtest_table_ent mtest_table[] = {
42 	{"normal",	memory_test_normal},
43 	{"quick",	memory_test_quick},
44 	{"extended",	memory_test_extended},
45 };
46 
47 static char **opt_array;
48 
49 char **
mtest_build_opts(int * maxerr_idx)50 mtest_build_opts(int *maxerr_idx)
51 {
52 	if (opt_array == NULL) {
53 		int nopts;
54 		/*
55 		 * Test "type" options here, max_errors should be the
56 		 * last one.
57 		 */
58 		nopts = sizeof (mtest_table) / sizeof (mtest_table[0]);
59 		*maxerr_idx = nopts;
60 
61 		/*
62 		 * One extra option for "max_errors"
63 		 */
64 		opt_array = (char **)malloc((nopts + 2) * sizeof (*opt_array));
65 		if (opt_array != NULL) {
66 			int i;
67 
68 			for (i = 0; i < nopts; i++)
69 				opt_array[i] = (char *)mtest_table[i].test_name;
70 
71 			opt_array[nopts] = "max_errors";
72 			opt_array[nopts + 1] = NULL;
73 		}
74 	}
75 	*maxerr_idx = sizeof (mtest_table) / sizeof (mtest_table[0]);
76 	return (opt_array);
77 }
78