1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright (C) 2018 IBM Corp. 3 4 #include <assert.h> 5 #include <sys/mman.h> 6 #include <sys/types.h> 7 #include <sys/stat.h> 8 #include <unistd.h> 9 10 #include "mboxd.h" 11 #include "protocol.h" 12 #include "transport_mbox.h" 13 14 #include "test/mbox.h" 15 #include "test/system.h" 16 17 #define FLAGS 0xc3 18 19 static const uint8_t get_info[] = { 20 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 21 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 22 }; 23 24 static const uint8_t command[] = { 25 0x09, 0xaa, FLAGS, 0x00, 0x00, 0x00, 0x00, 0x00, 26 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, FLAGS 27 }; 28 29 uint8_t data[3] = { 0xaa, 0x55, 0xaa }; 30 31 #define MEM_SIZE 3 32 #define ERASE_SIZE 1 33 #define N_WINDOWS 1 34 #define WINDOW_SIZE 1 35 36 int main(void) 37 { 38 struct mbox_context *ctx; 39 struct stat details; 40 uint8_t *map; 41 int rc; 42 43 system_set_reserved_size(MEM_SIZE); 44 system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE); 45 46 ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE); 47 rc = mbox_set_mtd_data(ctx, data, sizeof(data)); 48 assert(rc == 0); 49 50 rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info)); 51 assert(rc == 1); 52 53 protocol_events_set(ctx, FLAGS); 54 55 rc = mbox_command_dispatch(ctx, command, sizeof(command)); 56 assert(rc == 1); 57 58 rc = fstat(ctx->fds[MBOX_FD].fd, &details); 59 assert(rc == 0); 60 61 map = mmap(NULL, details.st_size, PROT_READ, MAP_PRIVATE, 62 ctx->fds[MBOX_FD].fd, 0); 63 assert(map != MAP_FAILED); 64 65 assert(details.st_size >= 16); 66 assert(map[15] == 0xc0); 67 68 return 0; 69 } 70