Simon Glass | 52d3df7 | 2020-09-12 11:13:34 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* |
| 3 | * Copyright (c) 2020, Heinrich Schuchardt <xypron.glpk@gmx.de> |
| 4 | * |
| 5 | * Header file for logging tests |
| 6 | */ |
| 7 | |
| 8 | #ifndef __SYSLOG_TEST_H |
| 9 | #define __SYSLOG_TEST_H |
| 10 | |
| 11 | #define LOGF_TEST (BIT(LOGF_FUNC) | BIT(LOGF_MSG)) |
| 12 | |
| 13 | /** |
| 14 | * struct sb_log_env - private data for sandbox ethernet driver |
| 15 | * |
| 16 | * This structure is used for the private data of the sandbox ethernet |
| 17 | * driver. |
| 18 | * |
| 19 | * @expected: string expected to be written by the syslog driver |
| 20 | * @uts: unit test state |
| 21 | */ |
| 22 | struct sb_log_env { |
| 23 | const char *expected; |
| 24 | struct unit_test_state *uts; |
| 25 | }; |
| 26 | |
| 27 | /** |
| 28 | * sb_log_tx_handler() - transmit callback function |
| 29 | * |
| 30 | * This callback function is invoked when a network package is sent using the |
| 31 | * sandbox Ethernet driver. The private data of the driver holds a sb_log_env |
| 32 | * structure with the unit test state and the expected UDP payload. |
| 33 | * |
| 34 | * The following checks are executed: |
| 35 | * |
| 36 | * * the Ethernet packet indicates a IP broadcast message |
| 37 | * * the IP header is for a local UDP broadcast message to port 514 |
| 38 | * * the UDP payload matches the expected string |
| 39 | * |
| 40 | * After testing the pointer to the expected string is set to NULL to signal |
| 41 | * that the callback function has been called. |
| 42 | * |
| 43 | * @dev: sandbox ethernet device |
| 44 | * @packet: Ethernet packet |
| 45 | * @len: length of Ethernet packet |
| 46 | * Return: 0 = success |
| 47 | */ |
| 48 | int sb_log_tx_handler(struct udevice *dev, void *packet, unsigned int len); |
| 49 | |
Simon Glass | c7f5b85 | 2020-09-12 12:28:50 -0600 | [diff] [blame] | 50 | /** |
| 51 | * syslog_test_setup() - Enable syslog logging ready for tests |
| 52 | * |
| 53 | * @uts: Test state |
| 54 | * @return 0 if OK, -ENOENT if the syslog log driver is not found |
| 55 | */ |
| 56 | int syslog_test_setup(struct unit_test_state *uts); |
| 57 | |
| 58 | /** |
| 59 | * syslog_test_finish() - Disable syslog logging after tests |
| 60 | * |
| 61 | * @uts: Test state |
| 62 | * @return 0 if OK, -ENOENT if the syslog log driver is not found |
| 63 | */ |
| 64 | int syslog_test_finish(struct unit_test_state *uts); |
| 65 | |
Simon Glass | 52d3df7 | 2020-09-12 11:13:34 -0600 | [diff] [blame] | 66 | #endif |