1 /*
2 * This file is part of the flashrom project.
3 *
4 * Copyright 2021 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
16 #include "lifecycle.h"
17
18 #if CONFIG_DEDIPROG == 1
dediprog_libusb_init(void * state,libusb_context ** ctx)19 static int dediprog_libusb_init(void *state, libusb_context **ctx)
20 {
21 *ctx = not_null();
22 return 0;
23 }
24
dediprog_libusb_control_transfer(void * state,libusb_device_handle * devh,uint8_t bmRequestType,uint8_t bRequest,uint16_t wValue,uint16_t wIndex,unsigned char * data,uint16_t wLength,unsigned int timeout)25 static int dediprog_libusb_control_transfer(void *state,
26 libusb_device_handle *devh,
27 uint8_t bmRequestType,
28 uint8_t bRequest,
29 uint16_t wValue,
30 uint16_t wIndex,
31 unsigned char *data,
32 uint16_t wLength,
33 unsigned int timeout)
34 {
35 if (bRequest == 0x08 /* dediprog_cmds CMD_READ_PROG_INFO */) {
36 /* Provide dediprog Device String into data buffer */
37 memcpy(data, "SF600 V:7.2.2 ", wLength);
38 }
39 return wLength;
40 }
41
dediprog_basic_lifecycle_test_success(void ** state)42 void dediprog_basic_lifecycle_test_success(void **state)
43 {
44 struct io_mock_fallback_open_state dediprog_fallback_open_state = {
45 .noc = 0,
46 .paths = { LOCK_FILE },
47 };
48 const struct io_mock dediprog_io = {
49 .libusb_init = dediprog_libusb_init,
50 .libusb_control_transfer = dediprog_libusb_control_transfer,
51 .fallback_open_state = &dediprog_fallback_open_state,
52 };
53
54 run_basic_lifecycle(state, &dediprog_io, &programmer_dediprog, "voltage=3.5V");
55 }
56 #else
57 SKIP_TEST(dediprog_basic_lifecycle_test_success)
58 #endif /* CONFIG_DEDIPROG */
59