xref: /aosp_15_r20/external/flashrom/tests/io_mock.c (revision 0d6140be3aa665ecc836e8907834fcd3e3b018fc)
1 /*
2  * This file is part of the flashrom project.
3  *
4  * Copyright (C) 2021, Google Inc. All rights reserved.
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; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  */
16 
17 #include "io_mock.h"
18 
19 static const struct io_mock *current_io = NULL;
20 
io_mock_register(const struct io_mock * io)21 void io_mock_register(const struct io_mock *io)
22 {
23 	/* A test can either register its own mock open function or fallback_open_state. */
24 	assert_true(io == NULL || io->iom_open == NULL || io->fallback_open_state == NULL);
25 	current_io = io;
26 }
27 
get_io(void)28 const struct io_mock *get_io(void)
29 {
30 	return current_io;
31 }
32