1/**
2 * @file cpu_type_tests.c
3 *
4 * @remark Copyright 2003 OProfile authors
5 * @remark Read the file COPYING
6 *
7 * @author John Levon
8 * @author Philippe Elie
9 */
10
11#include <stddef.h>
12#include <stdio.h>
13#include <stdlib.h>
14#include <string.h>
15
16#include "op_cpu_type.h"
17
18static struct cpu_type {
19	char const * name;
20	op_cpu type;
21} cpu_str[] = {
22	{ "i386/ppro", CPU_PPRO },
23	{ "i386/pii", CPU_PII },
24	{ "i386/piii", CPU_PIII },
25	{ "i386/athlon", CPU_ATHLON },
26	{ "timer", CPU_TIMER_INT },
27	{ "rtc", CPU_RTC },
28	{ "i386/p4", CPU_P4 },
29	{ "ia64/ia64", CPU_IA64 },
30	{ "ia64/itanium", CPU_IA64_1 },
31	{ "ia64/itanium2", CPU_IA64_2 },
32	{ "x86-64/hammer", CPU_HAMMER },
33	{ "i386/p4-ht", CPU_P4_HT2 },
34	{ "alpha/ev4", CPU_AXP_EV4 },
35	{ "alpha/ev5", CPU_AXP_EV5 },
36	{ "alpha/pca56", CPU_AXP_PCA56 },
37	{ "alpha/ev6", CPU_AXP_EV6 },
38	{ "alpha/ev67", CPU_AXP_EV67 },
39	{ "foo", CPU_NO_GOOD },
40	{ "-3", CPU_NO_GOOD },
41	{ "2927", CPU_NO_GOOD },
42	{ "", CPU_NO_GOOD },
43	{ NULL, CPU_NO_GOOD }
44};
45
46
47static void test(struct cpu_type const * cpu)
48{
49	char const * name;
50	op_cpu type;
51
52	name = op_get_cpu_name(cpu->type);
53	if (cpu->type != CPU_NO_GOOD && strcmp(cpu->name, name)) {
54		printf("for %d expect %s found %s\n", cpu->type, cpu->name,
55		       name);
56		exit(EXIT_FAILURE);
57	}
58	if (cpu->type == CPU_NO_GOOD && strcmp("invalid cpu type", name)) {
59		printf("for %d expect %s found %s\n", cpu->type,
60		       "invalid cpu type", name);
61		exit(EXIT_FAILURE);
62	}
63
64	type = op_get_cpu_number(cpu->name);
65	if (type != cpu->type) {
66		printf("for %s expect %d found %d\n", cpu->name, cpu->type,
67		       type);
68		exit(EXIT_FAILURE);
69	}
70}
71
72
73int main(void)
74{
75	struct cpu_type * cpu;
76	for (cpu = cpu_str; cpu->name; ++cpu)
77		test(cpu);
78	return 0;
79}
80