blob: c3508c510f6ac081761b1baabc306ca4a8fcfade [file] [log] [blame]
Nikolai Artemiev702c58a2020-09-16 14:12:22 +10001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright 2020 Google LLC
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
Edward O'Callaghan629b8f02020-05-22 16:46:52 +100016#include <include/test.h>
17
18#include "programmer.h"
19
Anastasia Klimchuk2daeea22021-03-04 09:54:56 +110020#define assert_equal_and_free(text, expected) \
21 do { \
22 assert_string_equal(text, expected); \
23 free(text); \
24 } while (0)
25
26#define assert_not_equal_and_free(text, expected) \
27 do { \
28 assert_string_not_equal(text, expected); \
29 free(text); \
30 } while (0)
31
32
Edward O'Callaghan629b8f02020-05-22 16:46:52 +100033void flashbuses_to_text_test_success(void **state)
34{
35 (void) state; /* unused */
36
37 enum chipbustype bustype;
Anastasia Klimchuk2daeea22021-03-04 09:54:56 +110038 char *text;
Edward O'Callaghan629b8f02020-05-22 16:46:52 +100039
40 bustype = BUS_NONSPI;
Anastasia Klimchuk2daeea22021-03-04 09:54:56 +110041 text = flashbuses_to_text(bustype);
42 assert_equal_and_free(text, "Non-SPI");
Edward O'Callaghan629b8f02020-05-22 16:46:52 +100043
44 bustype |= BUS_PARALLEL;
Anastasia Klimchuk2daeea22021-03-04 09:54:56 +110045 text = flashbuses_to_text(bustype);
46 assert_not_equal_and_free(text, "Non-SPI, Parallel");
Edward O'Callaghan629b8f02020-05-22 16:46:52 +100047
48 bustype = BUS_PARALLEL;
49 bustype |= BUS_LPC;
Anastasia Klimchuk2daeea22021-03-04 09:54:56 +110050 text = flashbuses_to_text(bustype);
51 assert_equal_and_free(text, "Parallel, LPC");
Edward O'Callaghan629b8f02020-05-22 16:46:52 +100052
53 bustype |= BUS_FWH;
54 //BUS_NONSPI = BUS_PARALLEL | BUS_LPC | BUS_FWH,
Anastasia Klimchuk2daeea22021-03-04 09:54:56 +110055 text = flashbuses_to_text(bustype);
56 assert_equal_and_free(text, "Non-SPI");
Edward O'Callaghan629b8f02020-05-22 16:46:52 +100057
58 bustype |= BUS_SPI;
Anastasia Klimchuk2daeea22021-03-04 09:54:56 +110059 text = flashbuses_to_text(bustype);
60 assert_equal_and_free(text, "Parallel, LPC, FWH, SPI");
Edward O'Callaghan629b8f02020-05-22 16:46:52 +100061
62 bustype |= BUS_PROG;
Anastasia Klimchuk2daeea22021-03-04 09:54:56 +110063 text = flashbuses_to_text(bustype);
64 assert_equal_and_free(text,
65 "Parallel, LPC, FWH, SPI, Programmer-specific");
Edward O'Callaghan629b8f02020-05-22 16:46:52 +100066
67 bustype = BUS_NONE;
Anastasia Klimchuk2daeea22021-03-04 09:54:56 +110068 text = flashbuses_to_text(bustype);
69 assert_equal_and_free(text, "None");
Edward O'Callaghan629b8f02020-05-22 16:46:52 +100070}