1 /*- 2 * BSD LICENSE 3 * 4 * Copyright (c) Intel Corporation. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * * Neither the name of Intel Corporation nor the names of its 18 * contributors may be used to endorse or promote products derived 19 * from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #include "spdk/stdinc.h" 35 36 #include "spdk/scsi.h" 37 38 #include "CUnit/Basic.h" 39 40 #include "../common.c" 41 #include "iscsi/tgt_node.c" 42 #include "scsi/scsi_internal.h" 43 44 struct spdk_iscsi_globals g_spdk_iscsi; 45 46 const char *config_file; 47 48 bool 49 spdk_sock_is_ipv6(int sock) 50 { 51 return false; 52 } 53 54 bool 55 spdk_sock_is_ipv4(int sock) 56 { 57 return false; 58 } 59 60 struct spdk_iscsi_portal_grp * 61 spdk_iscsi_portal_grp_find_by_tag(int tag) 62 { 63 return NULL; 64 } 65 66 struct spdk_scsi_lun * 67 spdk_scsi_dev_get_lun(struct spdk_scsi_dev *dev, int lun_id) 68 { 69 if (lun_id < 0 || lun_id >= SPDK_SCSI_DEV_MAX_LUN) { 70 return NULL; 71 } 72 73 return dev->lun[lun_id]; 74 } 75 76 static void 77 config_file_fail_cases(void) 78 { 79 struct spdk_conf *config; 80 struct spdk_conf_section *sp; 81 char section_name[64]; 82 int section_index; 83 int rc; 84 85 config = spdk_conf_allocate(); 86 87 rc = spdk_conf_read(config, config_file); 88 CU_ASSERT(rc == 0); 89 90 section_index = 0; 91 while (true) { 92 snprintf(section_name, sizeof(section_name), "Failure%d", section_index); 93 sp = spdk_conf_find_section(config, section_name); 94 if (sp == NULL) { 95 break; 96 } 97 rc = spdk_cf_add_iscsi_tgt_node(sp); 98 CU_ASSERT(rc < 0); 99 section_index++; 100 } 101 102 spdk_conf_free(config); 103 } 104 105 int 106 main(int argc, char **argv) 107 { 108 CU_pSuite suite = NULL; 109 unsigned int num_failures; 110 111 if (argc < 2) { 112 fprintf(stderr, "usage: %s <config file>\n", argv[0]); 113 exit(1); 114 } 115 116 if (CU_initialize_registry() != CUE_SUCCESS) { 117 return CU_get_error(); 118 } 119 120 config_file = argv[1]; 121 122 suite = CU_add_suite("iscsi_target_node_suite", NULL, NULL); 123 if (suite == NULL) { 124 CU_cleanup_registry(); 125 return CU_get_error(); 126 } 127 128 if ( 129 CU_add_test(suite, "config file fail cases", config_file_fail_cases) == NULL 130 ) { 131 CU_cleanup_registry(); 132 return CU_get_error(); 133 } 134 135 CU_basic_set_mode(CU_BRM_VERBOSE); 136 CU_basic_run_tests(); 137 num_failures = CU_get_number_of_failures(); 138 CU_cleanup_registry(); 139 return num_failures; 140 } 141