aboutsummaryrefslogtreecommitdiffstats
path: root/tests/flashrom.c
blob: cc8883132d4506f507596529660cc8c7068ec6b2 (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
/*
 * This file is part of the flashrom project.
 *
 * Copyright 2020 Google LLC
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <include/test.h>
#include "tests.h"

#include "programmer.h"

#define assert_equal_and_free(text, expected)	\
	do {						\
		assert_string_equal(text, expected);	\
		free(text);				\
	} while (0)

#define assert_not_equal_and_free(text, expected)	\
	do {							\
		assert_string_not_equal(text, expected);	\
		free(text);					\
	} while (0)


void flashbuses_to_text_test_success(void **state)
{
	(void) state; /* unused */

	enum chipbustype bustype;
	char *text;

	bustype = BUS_NONSPI;
	text = flashbuses_to_text(bustype);
	assert_equal_and_free(text, "Non-SPI");

	bustype |= BUS_PARALLEL;
	text = flashbuses_to_text(bustype);
	assert_not_equal_and_free(text, "Non-SPI, Parallel");

	bustype = BUS_PARALLEL;
	bustype |= BUS_LPC;
	text = flashbuses_to_text(bustype);
	assert_equal_and_free(text, "Parallel, LPC");

	bustype |= BUS_FWH;
	//BUS_NONSPI = BUS_PARALLEL | BUS_LPC | BUS_FWH,
	text = flashbuses_to_text(bustype);
	assert_equal_and_free(text, "Non-SPI");

	bustype |= BUS_SPI;
	text = flashbuses_to_text(bustype);
	assert_equal_and_free(text, "Parallel, LPC, FWH, SPI");

	bustype |= BUS_PROG;
	text = flashbuses_to_text(bustype);
	assert_equal_and_free(text,
		"Parallel, LPC, FWH, SPI, Programmer-specific");

	bustype = BUS_NONE;
	text = flashbuses_to_text(bustype);
	assert_equal_and_free(text, "None");
}