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_mbox_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 get_mbox_info_response[] = { 34 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 35 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 36 }; 37 38 static const uint8_t get_flash_info0[] = { 39 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 40 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 41 }; 42 43 static const uint8_t get_flash_info_response0[] = { 44 0x03, 0x01, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 45 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 46 }; 47 48 static const uint8_t get_flash_info1[] = { 49 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 50 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 51 }; 52 53 static const uint8_t get_flash_info_response1[] = { 54 0x03, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 55 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 56 }; 57 58 #define MEM_SIZE 3 59 #define ERASE_SIZE 1 60 #define N_WINDOWS 1 61 #define WINDOW_SIZE 1 62 63 int main(void) 64 { 65 struct mbox_context *ctx; 66 int rc; 67 68 system_set_reserved_size(MEM_SIZE); 69 system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE); 70 71 ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE); 72 73 /* Consecutive GET_MBOX_INFOs can use "invalid" sequence numbers */ 74 rc = mbox_command_dispatch(ctx, get_mbox_info, sizeof(get_mbox_info)); 75 assert(rc == 1); 76 77 rc = mbox_cmp(ctx, get_mbox_info_response, 78 sizeof(get_mbox_info_response)); 79 assert(rc == 0); 80 81 rc = mbox_command_dispatch(ctx, get_mbox_info, sizeof(get_mbox_info)); 82 assert(rc == 1); 83 84 /* Other commands must use valid sequence numbers */ 85 rc = mbox_command_dispatch(ctx, get_flash_info0, 86 sizeof(get_flash_info0)); 87 assert(rc == 1); 88 89 rc = mbox_cmp(ctx, get_flash_info_response0, 90 sizeof(get_flash_info_response0)); 91 assert(rc == 0); 92 93 rc = mbox_command_dispatch(ctx, get_flash_info0, 94 sizeof(get_flash_info0)); 95 assert(rc == 8); 96 97 /* Retry with a "valid" sequence number */ 98 rc = mbox_command_dispatch(ctx, get_flash_info1, 99 sizeof(get_flash_info1)); 100 assert(rc == 1); 101 102 rc = mbox_cmp(ctx, get_flash_info_response1, 103 sizeof(get_flash_info_response1)); 104 assert(rc == 0); 105 106 return rc; 107 } 108