aboutsummaryrefslogtreecommitdiff
path: root/hw/ipmi/test/run-fru.c
blob: 9f65ed459a3befd6ce4af6042c058569cb89d616 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* Copyright 2013-2014 IBM Corp.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 	http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>

#define __TEST__

#include "../ipmi-fru.c"

int error = 0;

const char version[] = "a-too-long-version-test-string-is-here";

void ipmi_free_msg(struct ipmi_msg __unused *msg)
{
}

void ipmi_init_msg(struct ipmi_msg __unused *msg, int __unused interface,
		   uint32_t __unused code,
		   void __unused (*complete)(struct ipmi_msg *),
		   void __unused *user_data, size_t __unused req_size,
		   size_t __unused resp_size)
{
}

struct ipmi_msg *ipmi_mkmsg(int __unused interface, uint32_t __unused code,
			    void __unused (*complete)(struct ipmi_msg *),
			    void __unused *user_data, void __unused *req_data, size_t __unused req_size,
			    size_t __unused resp_size)
{
	return NULL;
}

int ipmi_queue_msg(struct ipmi_msg __unused *msg)
{
	return 0;
}

void _prlog(int __unused log_level, const __unused char* fmt, ...)
{
	return;
}

int main(void)
{
	u8 *buf;
	int len;
	struct product_info info = {
		.manufacturer = (char *) "IBM",
		.product = (char *) "skiboot",
		.part_no = (char *) "hello",
		.version = (char *) "12345",
		.serial_no = (char *) "12345",
		.asset_tag = (char *) "abcd",
	};
	struct product_info invalid_info = {
		.manufacturer = (char *) "I",
		.product = (char *) "skiboot",
		.part_no = (char *) "hello",
		.version = (char *) "12345",
		.serial_no = (char *) "12345",
		.asset_tag = (char *) "abcd",
	};
	struct product_info invalid_info2 = {
		.manufacturer = (char *) "IBM",
		.product = (char *) "skiboot",
		.part_no = (char *) "this is a really long string that's more"
		"than 32 characters, because it turns out that's invalid.",
		.version = (char *) "12345",
		.serial_no = (char *) "12345",
		.asset_tag = (char *) "abcd",
	};

	buf = malloc(256);

	len = fru_fill_product_info(buf, &info, 40);
	assert(len > 0);

	/* Make sure the checksum is right */
	assert(!fru_checksum(buf, len));

	/* This should fail (not enough space) */
	assert(fru_fill_product_info(buf, &info, 39) < 0);

	memset(buf, 0, 256);
	len = fru_fill_product_info(buf, &invalid_info, 40);
	assert(len == OPAL_PARAMETER);

	memset(buf, 0, 256);
	len = fru_fill_product_info(buf, &invalid_info2, 256);
	assert(len == OPAL_PARAMETER);

	memset(buf, 0, 256);
	assert(fru_add(buf, 256) > 0);

	memset(buf, 0, 256);
	assert(fru_add(buf, 1) == OPAL_PARAMETER);

	memset(buf, 0, 256);
	assert(fru_add(buf, 65) == OPAL_PARAMETER);

	free(buf);

	return 0;
}