1 /* 2 * MBox Daemon Test File 3 * 4 * Copyright 2017 IBM 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 */ 19 20 #include <assert.h> 21 22 #include "mbox.h" 23 #include "mboxd_msg.h" 24 25 #include "test/mbox.h" 26 #include "test/system.h" 27 28 static const uint8_t get_info[] = { 29 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 30 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 31 }; 32 33 static const uint8_t create_read_window_block_0[] = { 34 0x04, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 35 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 36 }; 37 38 static const uint8_t create_read_window_block_1[] = { 39 0x04, 0x02, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 40 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 41 }; 42 43 static const uint8_t create_read_window_block_2[] = { 44 0x04, 0x03, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 45 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 46 }; 47 48 uint8_t data[] = { 0x00, 0x01, 0x02 }; 49 50 #define MEM_SIZE sizeof(data) 51 #define ERASE_SIZE 1 52 #define N_WINDOWS MEM_SIZE - 1 53 #define WINDOW_SIZE 1 54 55 int main(void) 56 { 57 struct mbox_context *ctx; 58 int rc; 59 int i; 60 61 system_set_reserved_size(N_WINDOWS); 62 system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE); 63 64 ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE); 65 rc = mbox_set_mtd_data(ctx, data, sizeof(data)); 66 assert(rc == 0); 67 68 rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info)); 69 assert(rc == 1); 70 71 /* Make each block appear in each window */ 72 for (i = 0; i < 2; i++) { 73 rc = mbox_command_dispatch(ctx, create_read_window_block_0, 74 sizeof(create_read_window_block_0)); 75 assert(rc == 1); 76 assert(((uint8_t *)ctx->mem)[(0 + i) & 1] == data[0]); 77 78 rc = mbox_command_dispatch(ctx, create_read_window_block_1, 79 sizeof(create_read_window_block_1)); 80 assert(rc == 1); 81 assert(((uint8_t *)ctx->mem)[(1 + i) & 1] == data[1]); 82 83 rc = mbox_command_dispatch(ctx, create_read_window_block_2, 84 sizeof(create_read_window_block_2)); 85 assert(rc == 1); 86 assert(((uint8_t *)ctx->mem)[(2 + i) & 1] == data[2]); 87 } 88 89 return !(rc == 1); 90 }; 91