diff options
author | Evan Lojewski <github@meklort.com> | 2019-04-28 15:46:04 -0600 |
---|---|---|
committer | Evan Lojewski <github@meklort.com> | 2019-04-28 15:46:04 -0600 |
commit | 387a6bb8ff17554c4a54892b8de0c715a0b010a6 (patch) | |
tree | da3eb7b5af3d21a970f4466b160d5c9e6d742e55 /libs | |
parent | 729130d21d80081458e00722e98472c7ca2ce1fc (diff) | |
download | bcm5719-ortega-387a6bb8ff17554c4a54892b8de0c715a0b010a6.tar.gz bcm5719-ortega-387a6bb8ff17554c4a54892b8de0c715a0b010a6.zip |
Begin adding support for testing the NCSI library.
Diffstat (limited to 'libs')
-rw-r--r-- | libs/NCSI/CMakeLists.txt | 2 | ||||
-rw-r--r-- | libs/NCSI/tests/CMakeLists.txt | 50 | ||||
-rw-r--r-- | libs/NCSI/tests/tests.cpp | 163 | ||||
-rw-r--r-- | libs/NCSI/tests/valid_commands.c | 146 |
4 files changed, 361 insertions, 0 deletions
diff --git a/libs/NCSI/CMakeLists.txt b/libs/NCSI/CMakeLists.txt index eb0b768..67e9a1e 100644 --- a/libs/NCSI/CMakeLists.txt +++ b/libs/NCSI/CMakeLists.txt @@ -55,3 +55,5 @@ target_include_directories(${PROJECT_NAME} PUBLIC include) arm_add_library(${PROJECT_NAME}-arm STATIC ncsi.c) target_include_directories(${PROJECT_NAME}-arm PUBLIC ../../include) target_include_directories(${PROJECT_NAME}-arm PUBLIC include) + +add_subdirectory(tests)
\ No newline at end of file diff --git a/libs/NCSI/tests/CMakeLists.txt b/libs/NCSI/tests/CMakeLists.txt new file mode 100644 index 0000000..56d488d --- /dev/null +++ b/libs/NCSI/tests/CMakeLists.txt @@ -0,0 +1,50 @@ +################################################################################ +### +### @file libs/NCSI/tests/CMakeLists.txt +### +### @project +### +### @brief NCSI Test CMake file +### +################################################################################ +### +################################################################################ +### +### @copyright Copyright (c) 2019, Evan Lojewski +### @cond +### +### All rights reserved. +### +### Redistribution and use in source and binary forms, with or without +### modification, are permitted provided that the following conditions are met: +### 1. Redistributions of source code must retain the above copyright notice, +### this list of conditions and the following disclaimer. +### 2. Redistributions in binary form must reproduce the above copyright notice, +### this list of conditions and the following disclaimer in the documentation +### and/or other materials provided with the distribution. +### 3. Neither the name of the copyright holder nor the +### names of its contributors may be used to endorse or promote products +### derived from this software without specific prior written permission. +### +################################################################################ +### +### THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +### AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +### IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +### ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +### LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +### CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +### SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +### INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +### CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +### ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +### POSSIBILITY OF SUCH DAMAGE. +### @endcond +################################################################################ + +project(NCSI-tests) + +set(SOURCES valid_commands.c tests.cpp) + +simulator_add_executable(ncsi-tests ${SOURCES}) +target_link_libraries(ncsi-tests NCSI simulator gtest gtest_main) diff --git a/libs/NCSI/tests/tests.cpp b/libs/NCSI/tests/tests.cpp new file mode 100644 index 0000000..e67e572 --- /dev/null +++ b/libs/NCSI/tests/tests.cpp @@ -0,0 +1,163 @@ +#include "gtest/gtest.h" +// #include <APE_APE.h> +#include <APE_APE_PERI.h> +#include <Ethernet.h> +#include <NCSI.h> + + +#include <endian.h> + +uint32_t *gPacket; +uint32_t gPacketLen; + +uint32_t gTXPacket[0x300/4]; +uint32_t gTXPacketPos; + +extern uint8_t select_package1[]; +extern uint8_t clear_initial_state[]; +extern uint8_t disable_vlan[]; +extern uint8_t set_mac_addr[]; +extern uint8_t enable_bcast_filter[]; +extern uint8_t enable_network_tx[]; +extern uint8_t enable_channel[]; +extern uint8_t aen_enable[]; +extern uint8_t get_link_status_ch0[]; +extern uint8_t select_package2[]; +extern uint8_t get_link_status_ch1[]; +extern uint8_t get_link_status_ch2[]; +extern uint8_t get_link_status_ch3[]; +extern uint8_t disable_network_tx[]; +extern uint8_t disable_channel[]; +extern uint8_t deselect_package[]; + +extern uint32_t select_package1_len; +extern uint32_t clear_initial_state_len; +extern uint32_t disable_vlan_len; +extern uint32_t set_mac_addr_len; +extern uint32_t enable_bcast_filter_len; +extern uint32_t enable_network_tx_len; +extern uint32_t enable_channel_len; +extern uint32_t aen_enable_len; +extern uint32_t get_link_status_ch0_len; +extern uint32_t select_package2_len; +extern uint32_t get_link_status_ch1_len; +extern uint32_t get_link_status_ch2_len; +extern uint32_t get_link_status_ch3_len; +extern uint32_t disable_network_tx_len; +extern uint32_t disable_channel_len; +extern uint32_t deselect_package_len; + + +static uint32_t read_packet(uint32_t val, uint32_t offset, void *args) +{ + uint32_t data = 0; + if(gPacketLen > 0) + { + data = *gPacket; + gPacket++; + if(gPacketLen > 4) + { + gPacketLen -= 4; + } + else + { + gPacketLen = 0; + } + } + return htobe32(data); +} + +static uint32_t write_packet(uint32_t val, uint32_t offset, void *args) +{ + val = le32toh(val); + // printf("Writing packet %x\n", val); + gTXPacket[gTXPacketPos++] = le32toh(val); // Value from APE fw is in LE + return val; +} + +static uint32_t read_rx_status(uint32_t val, uint32_t offset, void *args) +{ + RegAPE_PERIBmcToNcRxStatus_t stat; + stat.r32 = 0; + stat.bits.New = gPacketLen ? 1 : 0; + stat.bits.PacketLength = gPacketLen; + + return stat.r32; +} + +static uint32_t read_tx_status(uint32_t val, uint32_t offset, void *args) +{ + RegAPE_PERIBmcToNcTxStatus_t stat; + stat.r32 = 0; + stat.bits.InFifo = sizeof(gTXPacket) - (gTXPacketPos*4); + + return stat.r32; +} + + + +void send_packet(uint8_t* packet, uint32_t len) +{ + gTXPacketPos = 0; // reset response position. + gPacket = (uint32_t*)packet; + gPacketLen = len; + + uint32_t buffer[1024]; + + RegAPE_PERIBmcToNcRxStatus_t stat; + stat.r32 = APE_PERI.BmcToNcRxStatus.r32; + // stat.print(); + + if(stat.bits.New) + { + int32_t bytes = stat.bits.PacketLength; + int i = 0; + while(bytes > 0) + { + uint32_t word = (APE_PERI.BmcToNcReadBuffer.r32); + buffer[i] = word; + // printf("Word %d: 0x%08X\n", i, word); + i++; + bytes -= 4; + } + + NetworkFrame_t *frame = ((NetworkFrame_t*)buffer); + + if(stat.bits.Bad) + { + // TODO: ACK bad packet. + APE_PERI.BmcToNcRxControl.bits.ResetBad = 1; + while(APE_PERI.BmcToNcRxControl.bits.ResetBad); + } + else if(!stat.bits.Passthru) + { + handleNCSIFrame(frame); + + EXPECT_EQ(gTXPacket[0], 0xffffffff); // Source MAC + EXPECT_EQ(gTXPacket[1], 0xffffffff); // Source/Dest MAC + EXPECT_EQ(gTXPacket[2], 0xffffffff); // Dest MAC + EXPECT_EQ(gTXPacket[3], 0x88f80001); // NCSI Type, Revision 1. + } + else + { + // Pass through to network + } + } +} + + +namespace { + +TEST(Packet, SelectPackage) { + APE_PERI.BmcToNcRxStatus.r32.installReadCallback(read_rx_status, NULL); + APE_PERI.BmcToNcReadBuffer.r32.installReadCallback(read_packet, NULL); + APE_PERI.BmcToNcTxStatus.r32.installReadCallback(read_tx_status, NULL); + + APE_PERI.BmcToNcTxBuffer.r32.installWriteCallback(write_packet, NULL); + APE_PERI.BmcToNcTxBufferLast.r32.installWriteCallback(write_packet, NULL); + + + send_packet(select_package1, select_package1_len); +} + +} // namespace diff --git a/libs/NCSI/tests/valid_commands.c b/libs/NCSI/tests/valid_commands.c new file mode 100644 index 0000000..1667f0f --- /dev/null +++ b/libs/NCSI/tests/valid_commands.c @@ -0,0 +1,146 @@ +#include <stdint.h> + + +// Select Packate +uint8_t select_package1[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x88, 0xf8, 0x00, 0x01, + 0x00, 0xed, 0x01, 0x1f, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0xff, 0xff, 0xfd, 0xee, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +uint32_t select_package1_len = sizeof(select_package1); + +// Clear Initial State +uint8_t clear_initial_state[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x88, 0xf8, 0x00, 0x01, + 0x00, 0xee, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xff, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +uint32_t clear_initial_state_len = sizeof(clear_initial_state); + +// Disable VLAN +uint8_t disable_vlan[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x88, 0xf8, 0x00, 0x01, + 0x00, 0xef, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xf2, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +uint32_t disable_vlan_len = sizeof(disable_vlan); + +// Set MAC Address +uint8_t set_mac_addr[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x88, 0xf8, 0x00, 0x01, + 0x00, 0xf0, 0x0e, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x09, + 0x4d, 0x00, 0x01, 0x4a, 0x01, 0x01, 0xff, 0xff, 0x75, 0xb3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +uint32_t set_mac_addr_len = sizeof(set_mac_addr); + +// Enable Broadcast Filter +uint8_t enable_bcast_filter[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x88, 0xf8, 0x00, 0x01, + 0x00, 0xf1, 0x10, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x0f, 0xff, 0xff, 0xee, 0xfb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +uint32_t enable_bcast_filter_len = sizeof(enable_bcast_filter); + +// Enable Network TX +uint8_t enable_network_tx[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x88, 0xf8, 0x00, 0x01, + 0x00, 0xf2, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xf9, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +uint32_t enable_network_tx_len = sizeof(enable_network_tx); + +// Enable Channel +uint8_t enable_channel[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x88, 0xf8, 0x00, 0x01, + 0x00, 0xf3, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xfc, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +uint32_t enable_channel_len = sizeof(enable_channel); + +// AEN Enable +uint8_t aen_enable[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x88, 0xf8, 0x00, 0x01, + 0x00, 0xf4, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xf6, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +uint32_t aen_enable_len = sizeof(aen_enable); + +// Get Link Status Ch0 +uint8_t get_link_status_ch0[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x88, 0xf8, 0x00, 0x01, + 0x00, 0xf5, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xf5, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +uint32_t get_link_status_ch0_len = sizeof(get_link_status_ch0); + +// Select Package +uint8_t select_package2[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x88, 0xf8, 0x00, 0x01, + 0x00, 0xf8, 0x01, 0x1f, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0xff, 0xff, 0xfd, 0xe3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +uint32_t select_package2_len = sizeof(select_package2); + +// Get Link Status Ch1 +uint8_t get_link_status_ch1[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x88, 0xf8, 0x00, 0x01, + 0x00, 0xfa, 0x0a, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xf5, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +uint32_t get_link_status_ch1_len = sizeof(get_link_status_ch1); + +// Get Link Status Ch2 +uint8_t get_link_status_ch2[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x88, 0xf8, 0x00, 0x01, + 0x00, 0xfb, 0x0a, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xf5, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +uint32_t get_link_status_ch2_len = sizeof(get_link_status_ch2); + +// Get Link Status Ch3 +uint8_t get_link_status_ch3[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x88, 0xf8, 0x00, 0x01, + 0x00, 0xfc, 0x0a, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xf5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +uint32_t get_link_status_ch3_len = sizeof(get_link_status_ch3); + +// Disable Network Tx +uint8_t disable_network_tx[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x88, 0xf8, 0x00, 0x01, + 0x00, 0xfd, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xf8, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +uint32_t disable_network_tx_len = sizeof(disable_network_tx); + +// Disable Channel +uint8_t disable_channel[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x88, 0xf8, 0x00, 0x01, + 0x00, 0xfe, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0xff, 0xff, 0xfa, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +uint32_t disable_channel_len = sizeof(disable_channel); + +// Deselect Package +uint8_t deselect_package[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x88, 0xf8, 0x00, 0x01, + 0x00, 0xff, 0x02, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xfc, 0xe1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +uint32_t deselect_package_len = sizeof(deselect_package); |