1*cbbc13c3SAndrew Jeffery /* 2*cbbc13c3SAndrew Jeffery * MBox Daemon Test File 3*cbbc13c3SAndrew Jeffery * 4*cbbc13c3SAndrew Jeffery * Copyright 2017 IBM 5*cbbc13c3SAndrew Jeffery * 6*cbbc13c3SAndrew Jeffery * Licensed under the Apache License, Version 2.0 (the "License"); 7*cbbc13c3SAndrew Jeffery * you may not use this file except in compliance with the License. 8*cbbc13c3SAndrew Jeffery * You may obtain a copy of the License at 9*cbbc13c3SAndrew Jeffery * 10*cbbc13c3SAndrew Jeffery * http://www.apache.org/licenses/LICENSE-2.0 11*cbbc13c3SAndrew Jeffery * 12*cbbc13c3SAndrew Jeffery * Unless required by applicable law or agreed to in writing, software 13*cbbc13c3SAndrew Jeffery * distributed under the License is distributed on an "AS IS" BASIS, 14*cbbc13c3SAndrew Jeffery * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15*cbbc13c3SAndrew Jeffery * See the License for the specific language governing permissions and 16*cbbc13c3SAndrew Jeffery * limitations under the License. 17*cbbc13c3SAndrew Jeffery * 18*cbbc13c3SAndrew Jeffery */ 19*cbbc13c3SAndrew Jeffery 20*cbbc13c3SAndrew Jeffery #include <assert.h> 21*cbbc13c3SAndrew Jeffery 22*cbbc13c3SAndrew Jeffery #include "mbox.h" 23*cbbc13c3SAndrew Jeffery #include "mboxd_msg.h" 24*cbbc13c3SAndrew Jeffery 25*cbbc13c3SAndrew Jeffery #include "test/mbox.h" 26*cbbc13c3SAndrew Jeffery #include "test/system.h" 27*cbbc13c3SAndrew Jeffery 28*cbbc13c3SAndrew Jeffery static const uint8_t get_mbox_info[] = { 29*cbbc13c3SAndrew Jeffery 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 30*cbbc13c3SAndrew Jeffery 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 31*cbbc13c3SAndrew Jeffery }; 32*cbbc13c3SAndrew Jeffery 33*cbbc13c3SAndrew Jeffery static const uint8_t get_mbox_info_response[] = { 34*cbbc13c3SAndrew Jeffery 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 35*cbbc13c3SAndrew Jeffery 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 36*cbbc13c3SAndrew Jeffery }; 37*cbbc13c3SAndrew Jeffery 38*cbbc13c3SAndrew Jeffery static const uint8_t get_flash_info0[] = { 39*cbbc13c3SAndrew Jeffery 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 40*cbbc13c3SAndrew Jeffery 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 41*cbbc13c3SAndrew Jeffery }; 42*cbbc13c3SAndrew Jeffery 43*cbbc13c3SAndrew Jeffery static const uint8_t get_flash_info_response0[] = { 44*cbbc13c3SAndrew Jeffery 0x03, 0x01, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 45*cbbc13c3SAndrew Jeffery 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 46*cbbc13c3SAndrew Jeffery }; 47*cbbc13c3SAndrew Jeffery 48*cbbc13c3SAndrew Jeffery static const uint8_t get_flash_info1[] = { 49*cbbc13c3SAndrew Jeffery 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 50*cbbc13c3SAndrew Jeffery 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 51*cbbc13c3SAndrew Jeffery }; 52*cbbc13c3SAndrew Jeffery 53*cbbc13c3SAndrew Jeffery static const uint8_t get_flash_info_response1[] = { 54*cbbc13c3SAndrew Jeffery 0x03, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 55*cbbc13c3SAndrew Jeffery 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 56*cbbc13c3SAndrew Jeffery }; 57*cbbc13c3SAndrew Jeffery 58*cbbc13c3SAndrew Jeffery #define MEM_SIZE 3 59*cbbc13c3SAndrew Jeffery #define ERASE_SIZE 1 60*cbbc13c3SAndrew Jeffery #define N_WINDOWS 1 61*cbbc13c3SAndrew Jeffery #define WINDOW_SIZE 1 62*cbbc13c3SAndrew Jeffery 63*cbbc13c3SAndrew Jeffery int main(void) 64*cbbc13c3SAndrew Jeffery { 65*cbbc13c3SAndrew Jeffery struct mbox_context *ctx; 66*cbbc13c3SAndrew Jeffery int rc; 67*cbbc13c3SAndrew Jeffery 68*cbbc13c3SAndrew Jeffery system_set_reserved_size(MEM_SIZE); 69*cbbc13c3SAndrew Jeffery system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE); 70*cbbc13c3SAndrew Jeffery 71*cbbc13c3SAndrew Jeffery ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE); 72*cbbc13c3SAndrew Jeffery 73*cbbc13c3SAndrew Jeffery /* Consecutive GET_MBOX_INFOs can use "invalid" sequence numbers */ 74*cbbc13c3SAndrew Jeffery rc = mbox_command_dispatch(ctx, get_mbox_info, sizeof(get_mbox_info)); 75*cbbc13c3SAndrew Jeffery assert(rc == 1); 76*cbbc13c3SAndrew Jeffery 77*cbbc13c3SAndrew Jeffery rc = mbox_cmp(ctx, get_mbox_info_response, 78*cbbc13c3SAndrew Jeffery sizeof(get_mbox_info_response)); 79*cbbc13c3SAndrew Jeffery assert(rc == 0); 80*cbbc13c3SAndrew Jeffery 81*cbbc13c3SAndrew Jeffery rc = mbox_command_dispatch(ctx, get_mbox_info, sizeof(get_mbox_info)); 82*cbbc13c3SAndrew Jeffery assert(rc == 1); 83*cbbc13c3SAndrew Jeffery 84*cbbc13c3SAndrew Jeffery /* Other commands must use valid sequence numbers */ 85*cbbc13c3SAndrew Jeffery rc = mbox_command_dispatch(ctx, get_flash_info0, 86*cbbc13c3SAndrew Jeffery sizeof(get_flash_info0)); 87*cbbc13c3SAndrew Jeffery assert(rc == 1); 88*cbbc13c3SAndrew Jeffery 89*cbbc13c3SAndrew Jeffery rc = mbox_cmp(ctx, get_flash_info_response0, 90*cbbc13c3SAndrew Jeffery sizeof(get_flash_info_response0)); 91*cbbc13c3SAndrew Jeffery assert(rc == 0); 92*cbbc13c3SAndrew Jeffery 93*cbbc13c3SAndrew Jeffery rc = mbox_command_dispatch(ctx, get_flash_info0, 94*cbbc13c3SAndrew Jeffery sizeof(get_flash_info0)); 95*cbbc13c3SAndrew Jeffery assert(rc == 8); 96*cbbc13c3SAndrew Jeffery 97*cbbc13c3SAndrew Jeffery /* Retry with a "valid" sequence number */ 98*cbbc13c3SAndrew Jeffery rc = mbox_command_dispatch(ctx, get_flash_info1, 99*cbbc13c3SAndrew Jeffery sizeof(get_flash_info1)); 100*cbbc13c3SAndrew Jeffery assert(rc == 1); 101*cbbc13c3SAndrew Jeffery 102*cbbc13c3SAndrew Jeffery rc = mbox_cmp(ctx, get_flash_info_response1, 103*cbbc13c3SAndrew Jeffery sizeof(get_flash_info_response1)); 104*cbbc13c3SAndrew Jeffery assert(rc == 0); 105*cbbc13c3SAndrew Jeffery 106*cbbc13c3SAndrew Jeffery return rc; 107*cbbc13c3SAndrew Jeffery } 108