/***************************************************************************** * Test %lX format *****************************************************************************/ void UT_osprintf_lX(void) { char *test_fmt = "lx"; /* Test format character(s) */ int i; struct { char *test_num; /* Test identifier; sequential numbers */ unsigned long int test_val; /* Test value */ int max_len; /* Maximum output string length */ char *format; /* Format string */ char *expected; /* Expected result */ char *description; /* Test description */ } osp_tests[] = { {"01", 0x9a8b7c6d, 8, "%lX", "9A8B7C6D", "%lX"}, {"02", 0xdd46ee21, 8, "$$$%lX$$$", "$$$DD46EE21$$$", "%lX embedded"}, {"03", 0x9ccc8275, 7, "%3lX", "9CCC8275", "%lX with minimum field size < number of digits"}, {"04", 0xbee33225, 10, "%.10lX", "00BEE33225", "%lX with precision field size"}, {"05", 0x123fdb, 7, "%9.7lX", " 0123FDB", "%lX with minimum and precision field size"}, {"06", 0xabc6543f, 16, "%-.20lX", "000000000000ABC6543F", "%lX with left-justify"}, {"07", -9876543, 5, "%lX", "FF694BC1", "%lX, negative value"}, {"08", 0x12b45, 3, "%8lX", " 12B45", "%lX with minimum field size > number of digits"}, {"09", 0x12b45, 2, "%08lX", "00012B45", "%lX with minimum field size > number of digits and leading zeroes"}, {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ }; for (i = 0; osp_tests[i].format[0] != '\0'; i++) { /* Perform sprintf test */ init_test(); SPRINTF(strg_buf, osp_tests[i].format, osp_tests[i].test_val); UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, osp_tests[i].test_num); /* Truncate expected string in preparation for snprintf test */ strcpy(trunc_buf, osp_tests[i].expected); if (strlen(trunc_buf) >= osp_tests[i].max_len) { trunc_buf[osp_tests[i].max_len - 1] = '\0'; } /* Perform snprintf test */ init_test(); SNPRINTF(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, osp_tests[i].test_num); } }
/***************************************************************************** * Test %p format *****************************************************************************/ void UT_osprintf_p(void) { char *test_fmt = "p"; /* Test format character(s) */ int i; struct { char *test_num; /* Test identifier; sequential numbers */ long int test_val; /* Test value */ int max_len; /* Maximum output string length */ char *format; /* Format string */ char *expected; /* Expected result */ char *description; /* Test description */ } osp_tests[] = { {"01", 98765, 5, "%p", "0x181cd", "%p"}, {"02", 46372, 10, "$$$%p$$$", "$$$0xb524$$$", "%p embedded"}, {"03", 91827, 5, "%3p", "0x166b3", "%p with minimum field size"}, {"04", 33225, 11, "%.10p", "0x00000081c9", "%p with precision field size"}, {"05", 12345, 9, "%9.7p", "0x0003039", "%p with minimum and precision field size"}, {"06", 98765, 19, "%-.20p", "0x000000000000000181cd", "%p with left-justify"}, {"07", -98765, 8, "%p", "0xfffe7e33", "%p, negative value"}, {"08", 4108, 4, "%8p", " 0x100c", "%p with minimum field size > number of digits"}, {"09", 55220, 6, "%010p", "0x0000d7b4", "%p with minimum field size > number of digits and leading zeroes"}, {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ }; for (i = 0; osp_tests[i].format[0] != '\0'; i++) { /* Perform sprintf test */ init_test(); sprintf(strg_buf, osp_tests[i].format, (void *) osp_tests[i].test_val); UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, osp_tests[i].test_num); /* Truncate expected string in preparation for snprintf test */ strcpy(trunc_buf, osp_tests[i].expected); if (strlen(trunc_buf) >= osp_tests[i].max_len) { trunc_buf[osp_tests[i].max_len - 1] = '\0'; } /* Perform snprintf test */ init_test(); snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, (void *) osp_tests[i].test_val); UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, osp_tests[i].test_num); } }
void test_lseek(void) { int fd, bufsiz, result, console; bufsiz = strlen(teststr) + 1; printf("lseek: Not a test........"); fd = open("fs_errno.txt", O_RDWR); result = lseek(fd, -10, SEEK_END); read(fd, buf, bufsiz); if (result == -1) { printf(" failed %d seek file\n", errno); } else if (fd != 3) { printf(" failed fd = %d, expect 3\n", fd); } else if (result != 79) { printf(" seek size %d mismatch %d\n", result, 79); } else if (strcmp(buf, "e program") != 0) { printf(" seek content mismatch\n"); } else { printf(" SUCCESS!\n"); } close(fd); fd = open("fs_errno.txt", O_RDONLY); console = open("con:", O_RDWR); printf("lseek: EBADF test........"); result = lseek(-1, 10, SEEK_SET); check_test(result, EBADF); printf("lseek: ESPIPE tes........"); result = lseek(console, 10, SEEK_SET); check_test(result, ESPIPE); printf("lseek: EINVAL test......."); result = lseek(fd, 10, 4); check_test(result, EINVAL); printf("lseek: EINVAL test......."); lseek(fd, 45, SEEK_SET); result = lseek(fd, -46, SEEK_CUR); check_test(result, EINVAL); printf("lseek: EINVAL test......."); result = lseek(fd, -bufsiz-1, SEEK_END); check_test(result, EINVAL); printf("lseek: EOF test.........."); result = lseek(fd, 1, SEEK_END); if (result == -1) { printf(" FAILURE!\n"); } else { printf(" SUCCESS!\n"); } }
int main(int argc, char **argv) { const char docstr[] = "Usage:\n" " test self-test\n" " test one N\n"; docopt_t doc = docopt(docstr, argc-1, argv+1, 0, DOCOPT_VERSION); unsigned long low = 0; unsigned long high = sizeof(tests)/sizeof(tests[0]); if (doc && !docopt_error(doc)) { if (docopt_get(doc, "one", 0)) { low = strtoul(docopt_get(doc, "N", 0)->fst, 0, 0); high = low + 1; fprintf(stdout, "ARGS\n"); for (int j = 0; tests[low].args[j]; ++j) fprintf(stdout, " %s\n", tests[low].args[j]); } } else { return 1; } docopt_free(doc); for (int i = low, e = high; i < e; ++i) { int argc = 0; for (int j = 0; tests[i].args[j]; ++j, ++argc) ; docopt_t doc = docopt(usages[tests[i].usage], argc, (char**)tests[i].args, DOCOPT_NO_HELP, DOCOPT_VERSION); if (!doc) { fprintf(stdout, "Failed to parse (%d):\n====\n%s\n====\n", i, usages[tests[i].usage]); return 1; } else if (docopt_error(doc)) { assert(docopt_error(doc) == DOCOPT_PRINTED_HELP); if (check_test(doc, i)) return 1; } else { if (check_test(doc, i)) return 1; } docopt_free(doc); } return 0; }
void parse_output (const struct target_opts* options, struct target_status* status) { char* out_name; FILE* data; assert (0 != status); assert (0 != options->argv [0]); out_name = output_name (options->argv [0]); data = fopen (out_name, "r"); if (0 == data) { if (ENOENT != errno) warn ("Error opening %s: %s\n", out_name, strerror (errno)); status->status = ST_NO_OUTPUT; } else { if (0 == options->data_dir || '\0' == *options->data_dir) { /* If there is not an input directory, look at the assertion tags */ if (!options->compat) check_test (data, status); else check_compat_test (data, status); } else { /* Otherwise, diff against the output file */ check_example (options->data_dir, out_name, data, status); } fclose (data); } free (out_name); }
void test_close(void) { int fd; printf("close: EBADF test........"); for (int i = 3; i < __OPEN_MAX; i++) { fd = close(i); if (fd == -1) { printf(" failed %d close %dth file\n", errno, i); break; } } fd = close(3); check_test(fd, EBADF); printf("close: EBADF test........"); fd = close(-1); check_test(fd, EBADF); }
static int execute_test(SSL_TEST_FIXTURE fixture) { int ret = 0; SSL_CTX *server_ctx = NULL, *server2_ctx = NULL, *client_ctx = NULL; SSL_TEST_CTX *test_ctx = NULL; HANDSHAKE_RESULT result; test_ctx = SSL_TEST_CTX_create(conf, fixture.test_app); if (test_ctx == NULL) goto err; #ifndef OPENSSL_NO_DTLS if (test_ctx->method == SSL_TEST_METHOD_DTLS) { server_ctx = SSL_CTX_new(DTLS_server_method()); if (test_ctx->servername_callback != SSL_TEST_SERVERNAME_CB_NONE) { server2_ctx = SSL_CTX_new(DTLS_server_method()); OPENSSL_assert(server2_ctx != NULL); } client_ctx = SSL_CTX_new(DTLS_client_method()); } #endif if (test_ctx->method == SSL_TEST_METHOD_TLS) { server_ctx = SSL_CTX_new(TLS_server_method()); if (test_ctx->servername_callback != SSL_TEST_SERVERNAME_CB_NONE) { server2_ctx = SSL_CTX_new(TLS_server_method()); OPENSSL_assert(server2_ctx != NULL); } client_ctx = SSL_CTX_new(TLS_client_method()); } OPENSSL_assert(server_ctx != NULL && client_ctx != NULL); OPENSSL_assert(CONF_modules_load(conf, fixture.test_app, 0) > 0); if (!SSL_CTX_config(server_ctx, "server") || !SSL_CTX_config(client_ctx, "client")) { goto err; } if (server2_ctx != NULL && !SSL_CTX_config(server2_ctx, "server2")) goto err; result = do_handshake(server_ctx, server2_ctx, client_ctx, test_ctx); ret = check_test(result, test_ctx); err: CONF_modules_unload(0); SSL_CTX_free(server_ctx); SSL_CTX_free(server2_ctx); SSL_CTX_free(client_ctx); SSL_TEST_CTX_free(test_ctx); if (ret != 1) ERR_print_errors_fp(stderr); return ret; }
void test_open(void) { int fd; printf("open: Not a test........."); fd = open("fs_errno.txt", O_RDWR | O_CREAT); if (fd < 0) { printf(" FAILURE!\n"); } else { printf(" SUCCESS!\n"); } close(fd); printf("open: ENODEV test........"); fd = open("kern:", O_RDONLY | O_CREAT); check_test(fd, ENODEV); printf("open: ENOENT test........"); fd = open("testcases/file.txt", O_RDONLY | O_CREAT); check_test(fd, ENOENT); printf("open: ENOENT test........"); fd = open("file.txt", O_RDONLY); check_test(fd, ENOENT); printf("open: EISDIR test........"); fd = open("testbin/", O_WRONLY); check_test(fd, EISDIR); printf("open: EEXIST test........"); fd = open("fs_errno.txt", O_RDONLY | O_CREAT | O_EXCL); check_test(fd, EEXIST); printf("open: EINVAL test........"); fd = open("fs_errno.txt", -1 ); check_test(fd, EINVAL); printf("open: EFAULT test........"); fd = open(NULL, O_RDWR | O_CREAT ); check_test(fd, EFAULT); printf("open: EMFILE test........"); int fda[__OPEN_MAX - 3]; for (int i = 0; i < __OPEN_MAX - 2; i++) { fda[i] = open("fs_errno.txt", O_RDONLY); if (fda[i] == -1) { printf(" failed %d open %dth file\n", errno, i); break; } } fd = open("fs_errno.txt", O_RDWR); check_test(fd, EMFILE); }
static int run_test(Teuchos::RCP<const Epetra_MultiVector> &coords, Teuchos::RCP<const Epetra_MultiVector> &weights, const Teuchos::ParameterList ¶ms) { Teuchos::RCP<Isorropia::Epetra::Partitioner> part = Teuchos::rcp(new Isorropia::Epetra::Partitioner(coords, weights, params)); return check_test(coords, weights, part); }
void test_read(void) { int fd, strsiz, result; strsiz = strlen(teststr) + 1; printf("read: Not a test........."); fd = open("fs_errno.txt", O_RDWR); result = read(fd, buf, strsiz); if (result == -1) { printf(" failed %d read file\n", errno); } else if (fd != 3) { printf(" failed fd = %d, expect 3\n", fd); } else if (result != strsiz) { printf(" read size %d mismatch %d\n", result, strsiz); } else if (strcmp(buf, teststr) != 0) { printf(" read content mismatch\n"); } else { printf(" SUCCESS!\n"); } close(fd); fd = open("fs_errno.txt", O_RDONLY); printf("read: EBADF test........."); result = read(-1, buf, 10); check_test(result, EBADF); printf("read: EBADF test........."); result = read(4, buf, 10); check_test(result, EBADF); void *broken = NULL; printf("read: EFAULT test........"); result = read(3, broken, 10); check_test(result, EFAULT); close(fd); fd = open("fs_errno.txt", O_WRONLY); printf("read: EBADF test........."); result = read(3, buf, 10); check_test(result, EBADF); close(fd); }
void test_dup2(void) { int fd, newfd, bufsiz, result; bufsiz = strlen(teststr) + 1; printf("dup2: Not a test........."); fd = open("fs_errno.txt", O_RDWR); newfd = __OPEN_MAX - 1; result = dup2(fd, newfd); read(fd, buf, 10); lseek(fd, -8, SEEK_END); close(fd); read(newfd, buf+10, bufsiz); if (result == -1) { printf(" failed %d dup2 file\n", errno); } else if (result != newfd) { printf(" failed result = %d, expect %d\n", result, newfd); } else if (strcmp(buf, "This is a program") != 0) { printf(" dup2 cursors are not synchronised\n"); } else { printf(" SUCCESS!\n"); } close(newfd); printf("dup2: EBADF test........."); result = dup2(fd, -1); check_test(result, EBADF); // Reallocate STDERR fd = open("fs_errno.txt", O_WRONLY); printf("dup2: STDERR reallocation"); result = dup2(fd, 2); close(fd); if (result == -1) { printf(" FAILURE!\n"); } snprintf(buf, MAX_BUF, "Congratulation, you've passed all the test cases!\n ----------------------------------------\nPlease remove this file if you rerun the test cases.\n Thanks for using Roger's pleb test cases\n"); write(2, buf, strlen(buf)); close(2); printf(" SUCCESS!\n"); // Reallocate STDOUT -> STDIN printf("dup2: STDOUT reallocation"); result = dup2(1, 0); if (result == -1) { printf(" FAILURE!\n"); } else { close(1); snprintf(buf, 13, " SUCCESS!\n"); write(0, buf, 13); } }
void test_write(void) { int fd, bufsiz, result; bufsiz = strlen(teststr) + 1; printf("write: Not a test........"); fd = open("fs_errno.txt", O_WRONLY); result = write(fd, teststr, bufsiz); if (result == -1) { printf(" failed %d write file\n", errno); } else if (fd != 3) { printf(" failed fd = %d, expect 3\n", fd); } else { printf(" SUCCESS!\n"); } printf("write: EBADF test........"); result = write(-1, teststr, bufsiz); check_test(result, EBADF); printf("write: EBADF test........"); result = write(4, teststr, bufsiz); check_test(result, EBADF); void *broken = NULL; printf("write: EFAULT test......."); result = write(3, broken, bufsiz); check_test(result, EFAULT); close(fd); fd = open("fs_errno.txt", O_RDONLY); printf("write: EBADF test........"); result = write(3, teststr, bufsiz); check_test(result, EBADF); close(fd); }
static int run_test(Teuchos::RCP<const Epetra_MultiVector> &coords, const Teuchos::ParameterList ¶ms) { Teuchos::RCP<Isorropia::Epetra::Partitioner> part = Teuchos::rcp(new Isorropia::Epetra::Partitioner(coords, params)); // both Zoltan and Isorropia partitioners will use unit weights, // so we create unit weights to compute balances Epetra_MultiVector tmp(coords->Map(), 1); tmp.PutScalar(1.0); Teuchos::RCP<const Epetra_MultiVector> unitweights = Teuchos::rcp(new const Epetra_MultiVector(tmp)); return check_test(coords, unitweights, part); }
/* Check the entire syntax tree. */ static void semcheck(stnode_t *st_node) { #ifdef DEBUG_dfilter static guint i = 0; #endif DebugLog((" 2 semcheck(stnode_t *st_node = %p) [%u]\n", st_node, i++)); /* The parser assures that the top-most syntax-tree * node will be a TEST node, no matter what. So assert that. */ switch (stnode_type_id(st_node)) { case STTYPE_TEST: check_test(st_node); break; default: g_assert_not_reached(); } }
void various_tests() { printf("Finished initializing\n"); checkTest(); illegal_move_test(); test_get_legal_moves(); make_test_suite(); see_test_suite(); check_test(); isLegal_test(); eval_test(); run_perft_test(); check_evasion_test(); hash_test(); do_eval(); //bookTest(); }
int test() { std::vector<std::string> neutrals; std::vector<std::string> ions; neutrals.push_back("N2"); neutrals.push_back("CH4"); ions.push_back("N2+"); ions.push_back("e"); Scalar chi(100.L); std::vector<Scalar> lambda_ref,phy1AU,phy_on_top; std::ifstream flux_1AU("./input/hv_SSI.dat"); std::string line; getline(flux_1AU,line); while(!flux_1AU.eof()) { Scalar wv,ir,dirr; flux_1AU >> wv >> ir >> dirr; if(!lambda_ref.empty() && wv == lambda_ref.back())continue; lambda_ref.push_back(wv);//nm phy1AU.push_back(ir);//W/m2/nm phy_on_top.push_back(ir/std::pow(Planet::Constants::Saturn::d_Sun<Scalar>(),2)); } flux_1AU.close(); Planet::Chapman<Scalar> chapman(chi); Planet::PhotonFlux<Scalar,std::vector<Scalar>, std::vector<std::vector<Scalar> > > photon(chapman); photon.set_photon_flux_top_atmosphere(lambda_ref,phy1AU,Planet::Constants::Saturn::d_Sun<Scalar>()); std::vector<Scalar> molar_frac = {0.96,0.04,0.,0.}; Scalar dens_tot(1e12); Planet::Atmosphere<Scalar, std::vector<Scalar>, std::vector<std::vector<Scalar> > > atm(neutrals,ions,photon); atm.make_altitude_grid(600.,1400.,10.); std::ifstream temp("input/temperature.dat"); std::vector<Scalar> T0,Tz; getline(temp,line); while(!temp.eof()) { Scalar t,tz,dt,dtz; temp >> t >> tz >> dt >> dtz; T0.push_back(t); Tz.push_back(tz); } temp.close(); atm.set_temperature(T0,Tz); std::vector<Scalar> T = atm.temperature_top_to_bottom(); std::vector<std::vector<Scalar> > MatrixTotalDensity; std::vector<Scalar> tot_dens = atm.total_density_top_to_bottom(); std::vector<Scalar> lambda_N2,sigma_N2; std::vector<std::vector<Scalar> > sigma_rate_N2; sigma_rate_N2.resize(3); std::ifstream sig_N2("./input/N2_hv_cross-sections.dat"); std::ifstream sig_CH4("./input/CH4_hv_cross-sections.dat"); getline(sig_N2,line); getline(sig_CH4,line); while(!sig_N2.eof()) { Scalar wv,sigt,sig1,sig2,sig3; sig_N2 >> wv >> sigt >> sig1 >> sig2 >> sig3; lambda_N2.push_back(wv/10.);//A -> nm sigma_N2.push_back(sigt*10.);//cm-2/A -> cm-2/nm sigma_rate_N2[0].push_back(sig1*10.); sigma_rate_N2[1].push_back(sig2*10.); sigma_rate_N2[2].push_back(sig3*10.); } sig_N2.close(); atm.add_photoabsorption("N2",lambda_N2,sigma_N2); std::vector<Scalar> lambda_CH4,sigma_CH4; std::vector<std::vector<Scalar> > sigma_rate_CH4; sigma_rate_CH4.resize(9); while(!sig_CH4.eof()) { Scalar wv,sigt,sig1,sig2,sig3,sig4,sig5,sig6,sig7,sig8,sig9; sig_CH4 >> wv >> sigt >> sig1 >> sig2 >> sig3 >> sig4 >> sig5 >> sig6 >> sig7 >> sig8 >> sig9; lambda_CH4.push_back(wv/10.);//A -> nm sigma_CH4.push_back(sigt*10.);//cm-2/A -> cm-2/nm sigma_rate_CH4[0].push_back(sig1*10.); sigma_rate_CH4[1].push_back(sig2*10.); sigma_rate_CH4[2].push_back(sig3*10.); sigma_rate_CH4[3].push_back(sig4*10.); sigma_rate_CH4[4].push_back(sig5*10.); sigma_rate_CH4[5].push_back(sig6*10.); sigma_rate_CH4[6].push_back(sig7*10.); sigma_rate_CH4[7].push_back(sig8*10.); sigma_rate_CH4[8].push_back(sig9*10.); } sig_CH4.close(); atm.add_photoabsorption("CH4",lambda_CH4,sigma_CH4); atm.init_composition(molar_frac,dens_tot); int return_flag(0); //Phy at top std::vector<Scalar> phy_top; phy_top.resize(lambda_ref.size(),0.L); for(unsigned int il = 0; il < lambda_ref.size(); il++) { phy_top[il] = phy1AU[il]/(Planet::Constants::Saturn::d_Sun<Scalar>() * Planet::Constants::Saturn::d_Sun<Scalar>()); if(check_test(phy_top[il],photon.phy_at_top()[il],"Photon flux at top"))return_flag = 1; } std::ofstream out("phy_z.dat"); std::ofstream out_the("phy_z_the.dat"); out_the << "z N_N N+_N N2+ sCH2_H2 CH3_H CH2_H_H CH4+ CH3+_H CH2+_H2 CH+_H2_H H+_CH3 CH_H2_H" << std::endl; std::vector<Scalar> lamb = atm.hv_flux().lambda(); std::vector<Scalar> sum_over_neutral; sum_over_neutral.resize(2,0.L); std::vector<Scalar> tau_theo; std::vector<Scalar> rate_N2,rate_CH4; rate_N2.resize(3); rate_CH4.resize(9); Scalar MN(14.008L), MC(12.011), MH(1.008L); Scalar MN2 = 2.L*MN , MCH4 = MC + 4.L*MH; unsigned int ialt(0); for(Scalar z = 1400.; z >= 600.; z -= 10.) { Scalar M_the = molar_frac[0] * MN2 + molar_frac[1] * MCH4; Scalar n_tot_the = dens_tot * std::exp(-(z - 600.) / ( (z + Planet::Constants::Titan::radius<Scalar>()) * (600. + Planet::Constants::Titan::radius<Scalar>()) * 1e3L * //to m ( (Planet::Constants::Universal::kb<Scalar>() * Antioch::Constants::Avogadro<Scalar>() * T[ialt]) / (Planet::Constants::Universal::G<Scalar>() * Planet::Constants::Titan::mass<Scalar>() * M_the * 1e-3L) //to kg/mol ) )); tau_theo.clear(); tau_theo.resize(lambda_ref.size(),0.L); for(unsigned int i = 0; i < 2; i++) { sum_over_neutral[i] += molar_frac[i] * n_tot_the; for(unsigned int il = 0; il < lambda_ref.size(); il++) { tau_theo[il] += sum_over_neutral[i] * atm.photon_sigma(i).y_on_custom()[il]; //filtering } } std::vector<Scalar> tau_cal = photon.tau(z,sum_over_neutral); for(unsigned int il = 0; il < lambda_ref.size(); il++) { tau_theo[il] *= chapman.chapman(atm.a(z)); if(check_test(tau_theo[il],tau_cal[il],"tau at altitude z"))return_flag = 1; } for(unsigned int ir = 0; ir < 3; ir++) { rate_N2[ir] = 0.L; for(unsigned int il = 0; il < lamb.size(); il++) { rate_N2[ir] += sigma_rate_N2[ir][il] * phy_on_top[il] * std::exp(-tau_theo[il]); } } for(unsigned int ir = 0; ir < 9; ir++) { rate_CH4[ir] = 0.L; for(unsigned int il = 0; il < lamb.size(); il++) { rate_CH4[ir] += sigma_rate_CH4[ir][il] * phy_on_top[il] * std::exp(-tau_theo[il]); } } std::vector<Scalar> phy_flux = atm.hv_flux().phy(z); for(unsigned int il = 0; il < phy_flux.size(); il++) { if(check_test(phy_on_top[il] * std::exp(-tau_theo[il]),phy_flux[il],"phy at altitude z and lambda"))return_flag = 1; out << lamb[il] << " " << phy_flux[il] << std::endl; } out_the << z << " "; for(unsigned int ir = 0; ir < 3; ir++) { out_the << rate_N2[ir] << " "; } for(unsigned int ir = 0; ir < 9; ir++) { out_the << rate_CH4[ir] << " "; } out_the << std::endl; out << std::endl; ialt++; } out.close(); out_the.close(); return return_flag; }
/***************************************************************************** * Test %x format *****************************************************************************/ void UT_osprintf_x(void) { char *test_fmt = "x"; /* Test format character(s) */ int i; #ifdef OSP_ARINC653 #pragma ghs nowarning 68 #endif struct { char *test_num; /* Test identifier; sequential numbers */ unsigned int test_val; /* Test value */ int max_len; /* Maximum output string length */ char *format; /* Format string */ char *expected; /* Expected result */ char *description; /* Test description */ } osp_tests[] = { {"01", 0xa8b7, 3, "%x", "a8b7", "%x"}, {"02", 0xff123, 10, "$$$%x$$$", "$$$ff123$$$", "%x embedded"}, {"03", 0xd1827, 5, "%3x", "d1827", "%x with minimum field size < number of digits"}, {"04", 0x3c225, 9, "%.10x", "000003c225", "%x with precision field size"}, {"05", 0x12b45, 9, "%9.7x", " 0012b45", "%x with minimum and precision field size"}, {"06", 0xe8a60, 19, "%-.20x", "000000000000000e8a60", "%x with left-justify"}, {"07", -16, 7, "%x", "fffffff0", "%x, negative value"}, {"08", 0x12b45, 3, "%8x", " 12b45", "%x with minimum field size > number of digits"}, {"09", 0x12b45, 5, "%08x", "00012b45", "%x with minimum field size > number of digits and leading zeroes"}, {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ }; #ifdef OSP_ARINC653 #pragma ghs endnowarning #endif for (i = 0; osp_tests[i].format[0] != '\0'; i++) { /* Perform sprintf test */ init_test(); sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, osp_tests[i].test_num); /* Truncate expected string in preparation for snprintf test */ strcpy(trunc_buf, osp_tests[i].expected); if (strlen(trunc_buf) >= osp_tests[i].max_len) { trunc_buf[osp_tests[i].max_len - 1] = '\0'; } /* Perform snprintf test */ init_test(); snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, osp_tests[i].test_num); } }
int BORINGSSL_self_test(void) { static const uint8_t kAESKey[16] = "BoringCrypto Key"; static const uint8_t kAESIV[16] = {0}; static const uint8_t kPlaintext[64] = "BoringCryptoModule FIPS KAT Encryption and Decryption Plaintext!"; static const uint8_t kAESCBCCiphertext[64] = { 0x87, 0x2d, 0x98, 0xc2, 0xcc, 0x31, 0x5b, 0x41, 0xe0, 0xfa, 0x7b, 0x0a, 0x71, 0xc0, 0x42, 0xbf, 0x4f, 0x61, 0xd0, 0x0d, 0x58, 0x8c, 0xf7, 0x05, 0xfb, 0x94, 0x89, 0xd3, 0xbc, 0xaa, 0x1a, 0x50, 0x45, 0x1f, 0xc3, 0x8c, 0xb8, 0x98, 0x86, 0xa3, 0xe3, 0x6c, 0xfc, 0xad, 0x3a, 0xb5, 0x59, 0x27, 0x7d, 0x21, 0x07, 0xca, 0x4c, 0x1d, 0x55, 0x34, 0xdd, 0x5a, 0x2d, 0xc4, 0xb4, 0xf5, 0xa8, #if !defined(BORINGSSL_FIPS_BREAK_AES_CBC) 0x35 #else 0x00 #endif }; static const uint8_t kAESGCMCiphertext[80] = { 0x4a, 0xd8, 0xe7, 0x7d, 0x78, 0xd7, 0x7d, 0x5e, 0xb2, 0x11, 0xb6, 0xc9, 0xa4, 0xbc, 0xb2, 0xae, 0xbe, 0x93, 0xd1, 0xb7, 0xfe, 0x65, 0xc1, 0x82, 0x2a, 0xb6, 0x71, 0x5f, 0x1a, 0x7c, 0xe0, 0x1b, 0x2b, 0xe2, 0x53, 0xfa, 0xa0, 0x47, 0xfa, 0xd7, 0x8f, 0xb1, 0x4a, 0xc4, 0xdc, 0x89, 0xf9, 0xb4, 0x14, 0x4d, 0xde, 0x95, 0xea, 0x29, 0x69, 0x76, 0x81, 0xa3, 0x5c, 0x33, 0xd8, 0x37, 0xd8, 0xfa, 0x47, 0x19, 0x46, 0x2f, 0xf1, 0x90, 0xb7, 0x61, 0x8f, 0x6f, 0xdd, 0x31, 0x3f, 0x6a, 0x64, #if !defined(BORINGSSL_FIPS_BREAK_AES_GCM) 0x0d #else 0x00 #endif }; static const DES_cblock kDESKey1 = {"BCMDESK1"}; static const DES_cblock kDESKey2 = {"BCMDESK2"}; static const DES_cblock kDESKey3 = {"BCMDESK3"}; static const DES_cblock kDESIV = {"BCMDESIV"}; static const uint8_t kDESCiphertext[64] = { 0xa4, 0x30, 0x7a, 0x4c, 0x1f, 0x60, 0x16, 0xd7, 0x4f, 0x41, 0xe1, 0xbb, 0x27, 0xc4, 0x27, 0x37, 0xd4, 0x7f, 0xb9, 0x10, 0xf8, 0xbc, 0xaf, 0x93, 0x91, 0xb8, 0x88, 0x24, 0xb1, 0xf6, 0xf8, 0xbd, 0x31, 0x96, 0x06, 0x76, 0xde, 0x32, 0xcd, 0x29, 0x29, 0xba, 0x70, 0x5f, 0xea, 0xc0, 0xcb, 0xde, 0xc7, 0x75, 0x90, 0xe0, 0x0f, 0x5e, 0x2c, 0x0d, 0x49, 0x20, 0xd5, 0x30, 0x83, 0xf8, 0x08, #if !defined(BORINGSSL_FIPS_BREAK_DES) 0x5a #else 0x00 #endif }; static const uint8_t kPlaintextSHA1[20] = { 0xc6, 0xf8, 0xc9, 0x63, 0x1c, 0x14, 0x23, 0x62, 0x9b, 0xbd, 0x55, 0x82, 0xf4, 0xd6, 0x1d, 0xf2, 0xab, 0x7d, 0xc8, #if !defined(BORINGSSL_FIPS_BREAK_SHA_1) 0x28 #else 0x00 #endif }; static const uint8_t kPlaintextSHA256[32] = { 0x37, 0xbd, 0x70, 0x53, 0x72, 0xfc, 0xd4, 0x03, 0x79, 0x70, 0xfb, 0x06, 0x95, 0xb1, 0x2a, 0x82, 0x48, 0xe1, 0x3e, 0xf2, 0x33, 0xfb, 0xef, 0x29, 0x81, 0x22, 0x45, 0x40, 0x43, 0x70, 0xce, #if !defined(BORINGSSL_FIPS_BREAK_SHA_256) 0x0f #else 0x00 #endif }; static const uint8_t kPlaintextSHA512[64] = { 0x08, 0x6a, 0x1c, 0x84, 0x61, 0x9d, 0x8e, 0xb3, 0xc0, 0x97, 0x4e, 0xa1, 0x9f, 0x9c, 0xdc, 0xaf, 0x3b, 0x5c, 0x31, 0xf0, 0xf2, 0x74, 0xc3, 0xbd, 0x6e, 0xd6, 0x1e, 0xb2, 0xbb, 0x34, 0x74, 0x72, 0x5c, 0x51, 0x29, 0x8b, 0x87, 0x3a, 0xa3, 0xf2, 0x25, 0x23, 0xd4, 0x1c, 0x82, 0x1b, 0xfe, 0xd3, 0xc6, 0xee, 0xb5, 0xd6, 0xaf, 0x07, 0x7b, 0x98, 0xca, 0xa7, 0x01, 0xf3, 0x94, 0xf3, 0x68, #if !defined(BORINGSSL_FIPS_BREAK_SHA_512) 0x14 #else 0x00 #endif }; static const uint8_t kRSASignature[256] = { 0x62, 0x66, 0x4b, 0xe3, 0xb1, 0xd2, 0x83, 0xf1, 0xa8, 0x56, 0x2b, 0x33, 0x60, 0x1e, 0xdb, 0x1e, 0x06, 0xf7, 0xa7, 0x1e, 0xa8, 0xef, 0x03, 0x4d, 0x0c, 0xf6, 0x83, 0x75, 0x7a, 0xf0, 0x14, 0xc7, 0xe2, 0x94, 0x3a, 0xb5, 0x67, 0x56, 0xa5, 0x48, 0x7f, 0x3a, 0xa5, 0xbf, 0xf7, 0x1d, 0x44, 0xa6, 0x34, 0xed, 0x9b, 0xd6, 0x51, 0xaa, 0x2c, 0x4e, 0xce, 0x60, 0x5f, 0xe9, 0x0e, 0xd5, 0xcd, 0xeb, 0x23, 0x27, 0xf8, 0xfb, 0x45, 0xe5, 0x34, 0x63, 0x77, 0x7f, 0x2e, 0x80, 0xcf, 0x9d, 0x2e, 0xfc, 0xe2, 0x50, 0x75, 0x29, 0x46, 0xf4, 0xaf, 0x91, 0xed, 0x36, 0xe1, 0x5e, 0xef, 0x66, 0xa1, 0xff, 0x27, 0xfc, 0x87, 0x7e, 0x60, 0x84, 0x0f, 0x54, 0x51, 0x56, 0x0f, 0x68, 0x99, 0xc0, 0x3f, 0xeb, 0xa5, 0xa0, 0x46, 0xb0, 0x86, 0x02, 0xb0, 0xc8, 0xe8, 0x46, 0x13, 0x06, 0xcd, 0xb7, 0x8a, 0xd0, 0x3b, 0x46, 0xd0, 0x14, 0x64, 0x53, 0x9b, 0x5b, 0x5e, 0x02, 0x45, 0xba, 0x6e, 0x7e, 0x0a, 0xb9, 0x9e, 0x62, 0xb7, 0xd5, 0x7a, 0x87, 0xea, 0xd3, 0x24, 0xa5, 0xef, 0xb3, 0xdc, 0x05, 0x9c, 0x04, 0x60, 0x4b, 0xde, 0xa8, 0x90, 0x08, 0x7b, 0x6a, 0x5f, 0xb4, 0x3f, 0xda, 0xc5, 0x1f, 0x6e, 0xd6, 0x15, 0xde, 0x65, 0xa4, 0x6e, 0x62, 0x9d, 0x8f, 0xa8, 0xbe, 0x86, 0xf6, 0x09, 0x90, 0x40, 0xa5, 0xf4, 0x23, 0xc5, 0xf6, 0x38, 0x86, 0x0d, 0x1c, 0xed, 0x4a, 0x0a, 0xae, 0xa4, 0x26, 0xc2, 0x2e, 0xd3, 0x13, 0x66, 0x61, 0xea, 0x35, 0x01, 0x0e, 0x13, 0xda, 0x78, 0x20, 0xae, 0x59, 0x5f, 0x9b, 0xa9, 0x6c, 0xf9, 0x1b, 0xdf, 0x76, 0x53, 0xc8, 0xa7, 0xf5, 0x63, 0x6d, 0xf3, 0xff, 0xfd, 0xaf, 0x75, 0x4b, 0xac, 0x67, 0xb1, 0x3c, 0xbf, 0x5e, 0xde, 0x73, 0x02, 0x6d, 0xd2, 0x0c, 0xb1, #if !defined(BORINGSSL_FIPS_BREAK_RSA_SIG) 0x64 #else 0x00 #endif }; const uint8_t kDRBGEntropy[48] = "BCM Known Answer Test DBRG Initial Entropy "; const uint8_t kDRBGPersonalization[18] = "BCMPersonalization"; const uint8_t kDRBGAD[16] = "BCM DRBG KAT AD "; const uint8_t kDRBGOutput[64] = { 0x1d, 0x63, 0xdf, 0x05, 0x51, 0x49, 0x22, 0x46, 0xcd, 0x9b, 0xc5, 0xbb, 0xf1, 0x5d, 0x44, 0xae, 0x13, 0x78, 0xb1, 0xe4, 0x7c, 0xf1, 0x96, 0x33, 0x3d, 0x60, 0xb6, 0x29, 0xd4, 0xbb, 0x6b, 0x44, 0xf9, 0xef, 0xd9, 0xf4, 0xa2, 0xba, 0x48, 0xea, 0x39, 0x75, 0x59, 0x32, 0xf7, 0x31, 0x2c, 0x98, 0x14, 0x2b, 0x49, 0xdf, 0x02, 0xb6, 0x5d, 0x71, 0x09, 0x50, 0xdb, 0x23, 0xdb, 0xe5, 0x22, #if !defined(BORINGSSL_FIPS_BREAK_DRBG) 0x95 #else 0x00 #endif }; const uint8_t kDRBGEntropy2[48] = "BCM Known Answer Test DBRG Reseed Entropy "; const uint8_t kDRBGReseedOutput[64] = { 0xa4, 0x77, 0x05, 0xdb, 0x14, 0x11, 0x76, 0x71, 0x42, 0x5b, 0xd8, 0xd7, 0xa5, 0x4f, 0x8b, 0x39, 0xf2, 0x10, 0x4a, 0x50, 0x5b, 0xa2, 0xc8, 0xf0, 0xbb, 0x3e, 0xa1, 0xa5, 0x90, 0x7d, 0x54, 0xd9, 0xc6, 0xb0, 0x96, 0xc0, 0x2b, 0x7e, 0x9b, 0xc9, 0xa1, 0xdd, 0x78, 0x2e, 0xd5, 0xa8, 0x66, 0x16, 0xbd, 0x18, 0x3c, 0xf2, 0xaa, 0x7a, 0x2b, 0x37, 0xf9, 0xab, 0x35, 0x64, 0x15, 0x01, 0x3f, 0xc4, }; const uint8_t kECDSASigR[32] = { 0x67, 0x80, 0xc5, 0xfc, 0x70, 0x27, 0x5e, 0x2c, 0x70, 0x61, 0xa0, 0xe7, 0x87, 0x7b, 0xb1, 0x74, 0xde, 0xad, 0xeb, 0x98, 0x87, 0x02, 0x7f, 0x3f, 0xa8, 0x36, 0x54, 0x15, 0x8b, 0xa7, 0xf5, #if !defined(BORINGSSL_FIPS_BREAK_ECDSA_SIG) 0x0c, #else 0x00, #endif }; const uint8_t kECDSASigS[32] = { 0xa5, 0x93, 0xe0, 0x23, 0x91, 0xe7, 0x4b, 0x8d, 0x77, 0x25, 0xa6, 0xba, 0x4d, 0xd9, 0x86, 0x77, 0xda, 0x7d, 0x8f, 0xef, 0xc4, 0x1a, 0xf0, 0xcc, 0x81, 0xe5, 0xea, 0x3f, 0xc2, 0x41, 0x7f, 0xd8, }; EVP_AEAD_CTX aead_ctx; EVP_AEAD_CTX_zero(&aead_ctx); RSA *rsa_key = NULL; EC_KEY *ec_key = NULL; ECDSA_SIG *sig = NULL; int ret = 0; AES_KEY aes_key; uint8_t aes_iv[16]; uint8_t output[256]; // AES-CBC Encryption KAT memcpy(aes_iv, kAESIV, sizeof(kAESIV)); if (AES_set_encrypt_key(kAESKey, 8 * sizeof(kAESKey), &aes_key) != 0) { goto err; } AES_cbc_encrypt(kPlaintext, output, sizeof(kPlaintext), &aes_key, aes_iv, AES_ENCRYPT); if (!check_test(kAESCBCCiphertext, output, sizeof(kAESCBCCiphertext), "AES-CBC Encryption KAT")) { goto err; } // AES-CBC Decryption KAT memcpy(aes_iv, kAESIV, sizeof(kAESIV)); if (AES_set_decrypt_key(kAESKey, 8 * sizeof(kAESKey), &aes_key) != 0) { goto err; } AES_cbc_encrypt(kAESCBCCiphertext, output, sizeof(kAESCBCCiphertext), &aes_key, aes_iv, AES_DECRYPT); if (!check_test(kPlaintext, output, sizeof(kPlaintext), "AES-CBC Decryption KAT")) { goto err; } size_t out_len; uint8_t nonce[EVP_AEAD_MAX_NONCE_LENGTH]; OPENSSL_memset(nonce, 0, sizeof(nonce)); if (!EVP_AEAD_CTX_init(&aead_ctx, EVP_aead_aes_128_gcm(), kAESKey, sizeof(kAESKey), 0, NULL)) { goto err; } // AES-GCM Encryption KAT if (!EVP_AEAD_CTX_seal(&aead_ctx, output, &out_len, sizeof(output), nonce, EVP_AEAD_nonce_length(EVP_aead_aes_128_gcm()), kPlaintext, sizeof(kPlaintext), NULL, 0) || !check_test(kAESGCMCiphertext, output, sizeof(kAESGCMCiphertext), "AES-GCM Encryption KAT")) { goto err; } // AES-GCM Decryption KAT if (!EVP_AEAD_CTX_open(&aead_ctx, output, &out_len, sizeof(output), nonce, EVP_AEAD_nonce_length(EVP_aead_aes_128_gcm()), kAESGCMCiphertext, sizeof(kAESGCMCiphertext), NULL, 0) || !check_test(kPlaintext, output, sizeof(kPlaintext), "AES-GCM Decryption KAT")) { goto err; } DES_key_schedule des1, des2, des3; DES_cblock des_iv; DES_set_key(&kDESKey1, &des1); DES_set_key(&kDESKey2, &des2); DES_set_key(&kDESKey3, &des3); // 3DES Encryption KAT memcpy(&des_iv, &kDESIV, sizeof(des_iv)); DES_ede3_cbc_encrypt(kPlaintext, output, sizeof(kPlaintext), &des1, &des2, &des3, &des_iv, DES_ENCRYPT); if (!check_test(kDESCiphertext, output, sizeof(kDESCiphertext), "3DES Encryption KAT")) { goto err; } // 3DES Decryption KAT memcpy(&des_iv, &kDESIV, sizeof(des_iv)); DES_ede3_cbc_encrypt(kDESCiphertext, output, sizeof(kDESCiphertext), &des1, &des2, &des3, &des_iv, DES_DECRYPT); if (!check_test(kPlaintext, output, sizeof(kPlaintext), "3DES Decryption KAT")) { goto err; } // SHA-1 KAT SHA1(kPlaintext, sizeof(kPlaintext), output); if (!check_test(kPlaintextSHA1, output, sizeof(kPlaintextSHA1), "SHA-1 KAT")) { goto err; } // SHA-256 KAT SHA256(kPlaintext, sizeof(kPlaintext), output); if (!check_test(kPlaintextSHA256, output, sizeof(kPlaintextSHA256), "SHA-256 KAT")) { goto err; } // SHA-512 KAT SHA512(kPlaintext, sizeof(kPlaintext), output); if (!check_test(kPlaintextSHA512, output, sizeof(kPlaintextSHA512), "SHA-512 KAT")) { goto err; } rsa_key = self_test_rsa_key(); if (rsa_key == NULL) { fprintf(stderr, "RSA KeyGen failed\n"); goto err; } // RSA Sign KAT unsigned sig_len; // Disable blinding for the power-on tests because it's not needed and // triggers an entropy draw. rsa_key->flags |= RSA_FLAG_NO_BLINDING; if (!RSA_sign(NID_sha256, kPlaintextSHA256, sizeof(kPlaintextSHA256), output, &sig_len, rsa_key) || !check_test(kRSASignature, output, sizeof(kRSASignature), "RSA Sign KAT")) { goto err; } // RSA Verify KAT if (!RSA_verify(NID_sha256, kPlaintextSHA256, sizeof(kPlaintextSHA256), kRSASignature, sizeof(kRSASignature), rsa_key)) { fprintf(stderr, "RSA Verify KAT failed.\n"); goto err; } ec_key = self_test_ecdsa_key(); if (ec_key == NULL) { fprintf(stderr, "ECDSA KeyGen failed\n"); goto err; } // ECDSA Sign/Verify PWCT // The 'k' value for ECDSA is fixed to avoid an entropy draw. ec_key->fixed_k = BN_new(); if (ec_key->fixed_k == NULL || !BN_set_word(ec_key->fixed_k, 42)) { fprintf(stderr, "Out of memory\n"); goto err; } sig = ECDSA_do_sign(kPlaintextSHA256, sizeof(kPlaintextSHA256), ec_key); uint8_t ecdsa_r_bytes[sizeof(kECDSASigR)]; uint8_t ecdsa_s_bytes[sizeof(kECDSASigS)]; if (sig == NULL || BN_num_bytes(sig->r) != sizeof(ecdsa_r_bytes) || !BN_bn2bin(sig->r, ecdsa_r_bytes) || BN_num_bytes(sig->s) != sizeof(ecdsa_s_bytes) || !BN_bn2bin(sig->s, ecdsa_s_bytes) || !check_test(kECDSASigR, ecdsa_r_bytes, sizeof(kECDSASigR), "ECDSA R") || !check_test(kECDSASigS, ecdsa_s_bytes, sizeof(kECDSASigS), "ECDSA S")) { fprintf(stderr, "ECDSA KAT failed.\n"); goto err; } // DBRG KAT CTR_DRBG_STATE drbg; if (!CTR_DRBG_init(&drbg, kDRBGEntropy, kDRBGPersonalization, sizeof(kDRBGPersonalization)) || !CTR_DRBG_generate(&drbg, output, sizeof(kDRBGOutput), kDRBGAD, sizeof(kDRBGAD)) || !check_test(kDRBGOutput, output, sizeof(kDRBGOutput), "DBRG Generate KAT") || !CTR_DRBG_reseed(&drbg, kDRBGEntropy2, kDRBGAD, sizeof(kDRBGAD)) || !CTR_DRBG_generate(&drbg, output, sizeof(kDRBGReseedOutput), kDRBGAD, sizeof(kDRBGAD)) || !check_test(kDRBGReseedOutput, output, sizeof(kDRBGReseedOutput), "DRBG Reseed KAT")) { goto err; } CTR_DRBG_clear(&drbg); CTR_DRBG_STATE kZeroDRBG; memset(&kZeroDRBG, 0, sizeof(kZeroDRBG)); if (!check_test(&kZeroDRBG, &drbg, sizeof(drbg), "DRBG Clear KAT")) { goto err; } ret = 1; err: EVP_AEAD_CTX_cleanup(&aead_ctx); RSA_free(rsa_key); EC_KEY_free(ec_key); ECDSA_SIG_free(sig); return ret; }
int tester() { //description std::vector<std::string> neutrals; std::vector<std::string> ions; neutrals.push_back("N2"); neutrals.push_back("CH4"); neutrals.push_back("C2H"); //ionic system contains neutral system ions = neutrals; ions.push_back("N2+"); Scalar MN(14.008L), MC(12.011), MH(1.008L); Scalar MN2 = 2.L*MN , MCH4 = MC + 4.L*MH, MC2H = 2.L * MC + MH; std::vector<Scalar> Mm; Mm.push_back(MN2); Mm.push_back(MCH4); Mm.push_back(MC2H); //densities std::vector<Scalar> molar_frac; molar_frac.push_back(0.95999L); molar_frac.push_back(0.04000L); molar_frac.push_back(0.00001L); molar_frac.push_back(0.L); Scalar dens_tot(1e12L); //hard sphere radius std::vector<Scalar> hard_sphere_radius; hard_sphere_radius.push_back(2.0675e-8L * 1e-2L); //N2 in cm -> m hard_sphere_radius.push_back(2.3482e-8L * 1e-2L); //CH4 in cm -> m hard_sphere_radius.push_back(0.L); //C2H //zenith angle //not necessary //photon flux //not necessary ////cross-section //not necessary //altitudes Scalar zmin(600.),zmax(1400.),zstep(10.); //binary diffusion Scalar bCN1(1.04e-5 * 1e-4),bCN2(1.76); //cm2 -> m2 Planet::DiffusionType CN_model(Planet::DiffusionType::Wakeham); Scalar bCC1(5.73e16 * 1e-4),bCC2(0.5); //cm2 -> m2 Planet::DiffusionType CC_model(Planet::DiffusionType::Wilson); Scalar bNN1(0.1783 * 1e-4),bNN2(1.81); //cm2 -> m2 Planet::DiffusionType NN_model(Planet::DiffusionType::Massman); /************************ * first level ************************/ //altitude Planet::Altitude<Scalar,std::vector<Scalar> > altitude(zmin,zmax,zstep); //neutrals Antioch::ChemicalMixture<Scalar> neutral_species(neutrals); //ions Antioch::ChemicalMixture<Scalar> ionic_species(ions); //chapman //not needed //binary diffusion Planet::BinaryDiffusion<Scalar> N2N2( Antioch::Species::N2, Antioch::Species::N2 , bNN1, bNN2, NN_model); Planet::BinaryDiffusion<Scalar> N2CH4( Antioch::Species::N2, Antioch::Species::CH4, bCN1, bCN2, CN_model); Planet::BinaryDiffusion<Scalar> CH4CH4( Antioch::Species::CH4, Antioch::Species::CH4, bCC1, bCC2, CC_model); Planet::BinaryDiffusion<Scalar> N2C2H( Antioch::Species::N2, Antioch::Species::C2H); Planet::BinaryDiffusion<Scalar> CH4C2H( Antioch::Species::CH4, Antioch::Species::C2H); std::vector<std::vector<Planet::BinaryDiffusion<Scalar> > > bin_diff_coeff; bin_diff_coeff.resize(2); bin_diff_coeff[0].push_back(N2N2); bin_diff_coeff[0].push_back(N2CH4); bin_diff_coeff[0].push_back(N2C2H); bin_diff_coeff[1].push_back(N2CH4); bin_diff_coeff[1].push_back(CH4CH4); bin_diff_coeff[1].push_back(CH4C2H); /************************ * second level ************************/ //temperature std::vector<Scalar> T0,Tz; read_temperature<Scalar>(T0,Tz,"input/temperature.dat"); std::vector<Scalar> neutral_temperature; linear_interpolation(T0,Tz,altitude.altitudes(),neutral_temperature); Planet::AtmosphericTemperature<Scalar, std::vector<Scalar> > temperature(neutral_temperature, neutral_temperature, altitude); //photon opacity //not needed //reaction sets //not needed /************************ * third level ************************/ //atmospheric mixture Planet::AtmosphericMixture<Scalar,std::vector<Scalar>, std::vector<std::vector<Scalar> > > composition(neutral_species, ionic_species, altitude, temperature); composition.init_composition(molar_frac,dens_tot); composition.set_hard_sphere_radius(hard_sphere_radius); composition.initialize(); //kinetics evaluators //not needed /************************ * fourth level ************************/ //photon evaluator //not needed //molecular diffusion Planet::MolecularDiffusionEvaluator<Scalar,std::vector<Scalar>, std::vector<std::vector<Scalar> > > molecular_diffusion(bin_diff_coeff, composition, altitude, temperature); molecular_diffusion.make_molecular_diffusion(); //eddy diffusion //not needed /************************ * checks ************************/ molar_frac.pop_back();//get the ion outta here Scalar Matm(0.L); for(unsigned int s = 0; s < molar_frac.size(); s++) { Matm += molar_frac[s] * composition.neutral_composition().M(s); } Matm *= 1e-3L; //to kg std::vector<std::vector<Scalar> > densities; calculate_densities(densities, dens_tot, molar_frac, zmin,zmax,zstep, temperature.neutral_temperature(), Mm); //N2, CH4, C2H std::vector<std::vector<Scalar> > Dij; Dij.resize(2); Dij[0].resize(3,0.L); Dij[1].resize(3,0.L); int return_flag(0); for(unsigned int iz = 0; iz < altitude.altitudes().size(); iz++) { Scalar P = pressure(composition.total_density()[iz],temperature.neutral_temperature()[iz]); Scalar T = temperature.neutral_temperature()[iz]; Dij[0][0] = binary_coefficient(T,P,bNN1,bNN2); //N2 N2 Dij[1][1] = binary_coefficient(T,P,bCC1 * Antioch::ant_pow(Planet::Constants::Convention::T_standard<Scalar>(),bCC2 + Scalar(1.L)) * Planet::Constants::Universal::kb<Scalar>() / Planet::Constants::Convention::P_normal<Scalar>(),bCC2 + Scalar(1.L)); //CH4 CH4 Dij[0][1] = binary_coefficient(T,P,bCN1 * Antioch::ant_pow(Planet::Constants::Convention::T_standard<Scalar>(),bCN2),bCN2); //N2 CH4 Dij[0][2] = binary_coefficient(Dij[0][0],Mm[0],Mm[2]); //N2 C2H Dij[1][2] = binary_coefficient(Dij[1][1],Mm[1],Mm[2]); //CH4 C2H Dij[1][0] = Dij[0][1]; //CH4 N2 for(unsigned int s = 0; s < molar_frac.size(); s++) { Scalar tmp(0.L); Scalar M_diff(0.L); for(unsigned int medium = 0; medium < 2; medium++) { if(s == medium)continue; tmp += densities[medium][iz]/Dij[medium][s]; } Scalar Ds = (barometry(zmin,altitude.altitudes()[iz],neutral_temperature[iz],Matm,dens_tot) - densities[s][iz]) / tmp; for(unsigned int j = 0; j < molar_frac.size(); j++) { if(s == j)continue; M_diff += composition.total_density()[iz] * composition.neutral_molar_fraction()[j][iz] * composition.neutral_composition().M(j); } M_diff /= Scalar(molar_frac.size() - 1); Scalar Dtilde = Ds / (Scalar(1.L) - composition.neutral_molar_fraction()[s][iz] * (Scalar(1.L) - composition.neutral_composition().M(s)/M_diff)); return_flag = return_flag || check_test(Dtilde,molecular_diffusion.Dtilde()[s][iz],"D tilde of species at altitude"); } return_flag = return_flag || check_test(Dij[0][0],molecular_diffusion.binary_coefficient(0,0,T,P),"binary molecular coefficient N2 N2 at altitude") || check_test(Dij[0][1],molecular_diffusion.binary_coefficient(0,1,T,P),"binary molecular coefficient N2 CH4 at altitude") || check_test(Dij[0][2],molecular_diffusion.binary_coefficient(0,2,T,P),"binary molecular coefficient N2 C2H at altitude") || check_test(Dij[1][1],molecular_diffusion.binary_coefficient(1,1,T,P),"binary molecular coefficient CH4 CH4 at altitude") || check_test(Dij[1][2],molecular_diffusion.binary_coefficient(1,2,T,P),"binary molecular coefficient CH4 C2H at altitude"); } return return_flag; }
/***************************************************************************** * Test %f format *****************************************************************************/ void UT_osprintf_f(void) { char *test_fmt = "f"; /* Test format character(s) */ int i; struct { char *test_num; /* Test identifier; sequential numbers */ float test_val; /* Test value */ int max_len; /* Maximum output string length */ char *format; /* Format string */ char *expected; /* Expected result */ char *description; /* Test description */ } osp_tests[] = { {"01", 5.230, 6, "%f", "5.230000", "%f, positive value"}, {"02", 2.1056, 9, "$$$%f$$$", "$$$2.105600$$$", "%f embedded, positive value"}, {"03", 91827.3, 4, "%3f", "91827.296875", "%f with maximum field size, positive value"}, {"04", 5.82345, 5, "%.3f", "5.823", "%f with minimum field size, positive value"}, {"05", 12.6789, 8, "%9.5f", " 12.67890", "%f with minimum and maximum field size, positive value"}, {"06", 65.5678, 13, "%-20.5f", "65.56780 ", "%f with left-justify, positive value"}, {"07", 2.7944, 8, "%+f", "+2.794400", "%f with sign, positive value"}, {"08", -0.6712237, 7, "%f", "-0.671224", "%f, negative value"}, {"09", -7.1109, 8, "$$$%f$$$", "$$$-7.110900$$$", "%f embedded, negative value"}, {"10", -918.987, 6, "%3f", "-918.987000", "%f with maximum field size, negative value"}, {"11", -3.1415, 3, "%.2f", "-3.14", "%f with precision, negative value"}, {"12", -1.23456, 6, "%9.7f", "-1.2345600", "%f with precision and maximum field size, negative value"}, {"13", -65.65, 5, "%-8.3f", "-65.650 ", "%f with left-justify, negative value"}, {"14", 0.0, 4, "%f", "0.000000", "%f, zero value"}, {"15", 4.0, 6, "%7.0f", " 4", "%f, no fraction, positive value"}, {"16", -56.0, 6, "%6.0f", " -56", "%f, no fraction, negative value"}, {"17", 4887.12, 5, "%010.3f", "004887.120", "%f with zero padding, positive value"}, {"18", -4887.12, 5, "%010.3f", "-04887.120", "%f with zero padding, negative value"}, {"19", 0.0, 6, "%06.2f", "000.00", "%f, with zero padding, zero value"}, {"20", 4.0, 6, "%07.0f", "0000004", "%f, zero padding, no fraction, positive value"}, {"21", -56.0, 6, "%06.0f", "-00056", "%f, zero padding, no fraction, negative value"}, {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ }; for (i = 0; osp_tests[i].format[0] != '\0'; i++) { /* Perform sprintf test */ init_test(); SPRINTF(strg_buf, osp_tests[i].format, osp_tests[i].test_val); UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, osp_tests[i].test_num); /* Truncate expected string in preparation for snprintf test */ strcpy(trunc_buf, osp_tests[i].expected); if (strlen(trunc_buf) >= osp_tests[i].max_len) { trunc_buf[osp_tests[i].max_len - 1] = '\0'; } /* Perform snprintf test */ init_test(); SNPRINTF(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, osp_tests[i].test_num); } }
/***************************************************************************** * Test %i format *****************************************************************************/ void UT_osprintf_i(void) { char *test_fmt = "i"; /* Test format character(s) */ int i; struct { char *test_num; /* Test identifier; sequential numbers */ int test_val; /* Test value */ int max_len; /* Maximum output string length */ char *format; /* Format string */ char *expected; /* Expected result */ char *description; /* Test description */ } osp_tests[] = { {"01", 98765, 5, "%i", "98765", "%i, positive value"}, {"02", 46372, 9, "$$$%i$$$", "$$$46372$$$", "%i embedded, positive value"}, {"03", 98765, 5, "% i", " 98765", "%i with space for sign, positive value"}, {"04", 91827, 7, "%8i", " 91827", "%i with minimum field size > number of digits, positive value"}, {"05", 91827, 2, "%4i", "91827", "%i with minimum field size < number of digits, positive value"}, {"06", 33225, 7, "%.10i", "0000033225", "%i with precision field size > number of digits, positive value"}, {"07", 33225, 3, "%.3i", "33225", "%i with precision field size < number of digits, positive value"}, {"08", 12345, 5, "%9.7i", " 0012345", "%i with minimum field size > precision field size > number of digits, positive value"}, {"09", 12345, 5, "%9.3i", " 12345", "%i with minimum field size > number of digits > precision field size, positive value"}, {"10", 12345, 5, "%4.2i", "12345", "%i with number of digits > minimum field size > precision field size, positive value"}, {"11", 12345, 8, "%7.9i", "000012345", "%i with precision field size > minimum field size > number of digits, positive value"}, {"12", 12345, 7, "%3.9i", "000012345", "%i with precision field size > number of digits > minimum field size, positive value"}, {"13", 12345, 4, "%2.4i", "12345", "%i with number of digits > precision field size > minimum field size, positive value"}, {"14", 98765, 5, "%-.20i", "00000000000000098765", "%i with left-justify and precision field size > number of digits, positive value"}, {"15", 98765, 5, "%-.3i", "98765", "%i with left-justify and precision field size < number of digits, positive value"}, {"16", 98765, 5, "%+i", "+98765", "%i with sign, positive value"}, {"17", 46372, 5, "$$$%+d$$$", "$$$+46372$$$", "%i sign and embedded, positive value"}, {"18", 91827, 6, "%+8i", " +91827", "%i with sign and minimum field size > number of digits, positive value"}, {"19", 91827, 4, "%+4i", "+91827", "%i with sign and minimum field size < number of digits, positive value"}, {"20", 33225, 8, "%+.10i", "+0000033225", "%i with sign and precision field size > number of digits, positive value"}, {"21", 33225, 5, "%+.3i", "+33225", "%i with sign and precision field size < number of digits, positive value"}, {"22", 12345, 5, "%+9.7i", " +0012345", "%i with sign and minimum field size > precision field size > number of digits, positive value"}, {"23", 12345, 5, "%+9.3i", " +12345", "%i with sign and minimum field size > number of digits > precision field size, positive value"}, {"24", 12345, 5, "%+4.2i", "+12345", "%i with sign and number of digits > minimum field size > precision field size, positive value"}, {"25", 12345, 8, "%+7.9i", "+000012345", "%i with sign and precision field size > minimum field size > number of digits, positive value"}, {"26", 12345, 7, "%+3.9i", "+000012345", "%i with sign and precision field size > number of digits > minimum field size, positive value"}, {"27", 12345, 5, "%+2.4i", "+12345", "%i with sign and number of digits > precision field size > minimum field size, positive value"}, {"28", 98765, 16, "%+-.20i", "+00000000000000098765", "%i with sign and left-justify and precision field size > number of digits, positive value"}, {"29", 98765, 5, "%+-.3i", "+98765", "%i with sign and left-justify and precision field size < number of digits, positive value"}, {"30", 98765, 4, "%+i", "+98765", "%i with sign, positive value"}, {"31", -98765, 6, "%i", "-98765", "%i, negative value"}, {"32", -46372, 6, "$$$%i$$$", "$$$-46372$$$", "%i embedded, negative value"}, {"33", -98765, 5, "% i", "-98765", "%i with space for sign, negative value"}, {"34", -91827, 9, "%10i", " -91827", "%i with minimum field size > number of digits, negative value"}, {"35", -91827, 6, "%4i", "-91827", "%i with minimum field size < number of digits, negative value"}, {"36", -33225, 9, "%.10i", "-0000033225", "%i with precision field size > number of digits, negative value"}, {"37", -33225, 5, "%.3i", "-33225", "%i with precision field size < number of digits, negative value"}, {"38", -12345, 8, "%9.7i", " -0012345", "%i with minimum field size > precision field size > number of digits, negative value"}, {"39", -12345, 7, "%9.3i", " -12345", "%i with minimum field size > number of digits > precision field size, negative value"}, {"40", -12345, 6, "%4.2i", "-12345", "%i with number of digits > minimum field size > precision field size, negative value"}, {"41", -12345, 7, "%7.9i", "-000012345", "%i with precision field size > minimum field size > number of digits, negative value"}, {"42", -12345, 8, "%3.9i", "-000012345", "%i with precision field size > number of digits > minimum field size, negative value"}, {"43", -12345, 5, "%2.4i", "-12345", "%i with number of digits > precision field size > minimum field size, negative value"}, {"44", -98765, 18, "%-.20i", "-00000000000000098765", "%i with left-justify and precision field size > number of digits, negative value"}, {"45", -98765, 5, "%-.3i", "-98765", "%i with left-justify and precision field size < number of digits, negative value"}, {"46", -98765, 6, "%+i", "-98765", "%i with sign, negative value"}, {"47", -46372, 7, "$$$%+d$$$", "$$$-46372$$$", "%i sign and embedded, negative value"}, {"48", -91827, 5, "%+8i", " -91827", "%i with sign and minimum field size > number of digits, negative value"}, {"49", -91827, 5, "%+4i", "-91827", "%i with sign and minimum field size < number of digits, negative value"}, {"50", -33225, 7, "%+.10i", "-0000033225", "%i with sign and precision field size > number of digits, negative value"}, {"51", -33225, 5, "%+.3i", "-33225", "%i with sign and precision field size < number of digits, negative value"}, {"52", -12345, 7, "%+9.7i", " -0012345", "%i with sign and minimum field size > precision field size > number of digits, negative value"}, {"53", -12345, 8, "%+9.3i", " -12345", "%i with sign and minimum field size > number of digits > precision field size, negative value"}, {"54", -12345, 4, "%+4.2i", "-12345", "%i with sign and number of digits > minimum field size > precision field size, negative value"}, {"55", -12345, 8, "%+7.9i", "-000012345", "%i with sign and precision field size > minimum field size > number of digits, negative value"}, {"56", -12345, 7, "%+3.9i", "-000012345", "%i with sign and precision field size > number of digits > minimum field size, negative value"}, {"57", -12345, 5, "%+2.4i", "-12345", "%i with sign and number of digits > precision field size > minimum field size, negative value"}, {"58", -98765, 19, "%+-.20i", "-00000000000000098765", "%i with sign and left-justify and precision field size > number of digits, negative value"}, {"59", -98765, 6, "%+-.3i", "-98765", "%i with sign and left-justify and precision field size < number of digits, negative value"}, {"60", -98765, 5, "%+i", "-98765", "%i with sign, negative value"}, {"61", 0, 6, "%i", "0", "%i, zero value"}, {"62", 162534, 5, "%08i", "00162534", "%i with zero padding, positive value"}, {"63", -162534, 6, "%08i", "-0162534", "%i with zero padding, negative value"}, {"64", 0, 6, "%04i", "0000", "%i, with zero padding, zero value"}, {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ }; for (i = 0; osp_tests[i].format[0] != '\0'; i++) { /* Perform sprintf test */ init_test(); SPRINTF(strg_buf, osp_tests[i].format, osp_tests[i].test_val); UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, osp_tests[i].test_num); /* Truncate expected string in preparation for snprintf test */ strcpy(trunc_buf, osp_tests[i].expected); if (strlen(trunc_buf) >= osp_tests[i].max_len) { trunc_buf[osp_tests[i].max_len - 1] = '\0'; } /* Perform snprintf test */ init_test(); SNPRINTF(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, osp_tests[i].test_num); } }
int main() { int size; mydisk_init("diskfile", MAX_BLOCKS, 0); init_cache(CACHED_BLOCKS); /* Test case 1: read/write block */ size = BLOCK_SIZE; memset(buffer, 0, size); strcpy(buffer, "hello world\n"); mydisk_write_block(0, buffer); memset(buffer2, 0, size); mydisk_read_block(0, buffer2); check_test(memcmp(buffer2, "hello world\n", 13)); /* Test case 2: basic read/write */ memset(buffer, 0, size); mydisk_read(0, 13, buffer); check_test(memcmp(buffer, "hello world\n", 13)); /* Test case 3: read in the middle */ memset(buffer, 0, BLOCK_SIZE); mydisk_read(8, 5, buffer); check_test(memcmp(buffer, "rld\n", 5)); /* Test case 4: read/write across blocks */ size = BLOCK_SIZE; rand_str(buffer, size); mydisk_write(144, size, buffer); memset(buffer2, 0, size); mydisk_read(144, size, buffer2); check_test(memcmp(buffer, buffer2, size)); /* Test case 5: large read/write */ size = BLOCK_SIZE * (MAX_BLOCKS - 1); rand_str(buffer, size); mydisk_write(276, size, buffer); mydisk_read(276, size, buffer2); check_test(memcmp(buffer, buffer2, size)); /* Test case 6~9: read/write exception */ check_test(!mydisk_read(-1, 0, buffer)); check_test(!mydisk_read(0, -10, buffer)); check_test(!mydisk_read(100, BLOCK_SIZE * MAX_BLOCKS, buffer)); check_test(mydisk_write(0, 0, buffer)); check_test(stress_test()); check_test(stress_test2()); close_cache(); mydisk_close(); return 0; }
int run_tests() { int i; int success = 0, total = 0; for (i = 0; i < (sizeof(cases) / sizeof(cases[0])); i++) { uint8_t buf[128], *rp, unpack[512], more_data[1500]; struct ip6_packet packet; struct ieee154_frame_addr fr, result_fr; struct lowpan_reconstruct recon; struct lowpan_ctx ctx; struct ip_iovec v[2]; int rv; memset(buf, 0, sizeof(buf)); total++; printf("\n\n----- Test case %i ----\n", i+1); packet.ip6_data = &v[0]; v[0].iov_next = &v[1]; v[0].iov_base= data; v[0].iov_len = 12; for (rv = 0; rv < sizeof(more_data); rv++) more_data[rv] = rv; v[1].iov_next = NULL; v[1].iov_base= more_data; v[1].iov_len = 1500; // print_buffer(more_data, 1500); setup_test(&cases[i], &packet.ip6_hdr, &fr, &v[0]); printf("IEEE 802.15.4 frame: "); print_buffer(&fr, sizeof(struct ieee154_frame_addr)); printf("\n"); printf("IPv6 Header:\n"); print_buffer(&packet.ip6_hdr, sizeof(struct ip6_hdr)); printf("\n"); printf("Data:\n"); print_buffer(data, 12); printf("\n"); printf("plen: %i\n", ntohs(packet.ip6_hdr.ip6_plen)); ctx.offset = 0; ctx.tag = 25; recon.r_buf = NULL; /* how you fragment a packet */ while ((rv = lowpan_frag_get(buf, sizeof(buf), &packet, &fr, &ctx)) > 0) { // print_buffer(buf, rv); /* how you unfragment a packet */ rp = unpack_ieee154_hdr(buf, &result_fr); printf("unpacked ieee154_header: %p-%p\n", buf, rp); // print_buffer(&result_fr, sizeof(result_fr)); if (recon.r_buf == NULL) { lowpan_recon_start(&result_fr, &recon, rp, rv - (rp - buf)); } else { lowpan_recon_add(&recon, rp, rv - (rp - buf)); } memset(buf, 0, sizeof(buf)); } printf("recon progress: %i %i\n", recon.r_bytes_rcvd, recon.r_size); print_buffer(recon.r_buf, recon.r_bytes_rcvd); if (recon.r_bytes_rcvd == recon.r_size) { if (check_test(&packet, &recon) == 0) { success++; } } free(recon.r_buf); recon.r_buf = NULL; } printf("%s: %i/%i tests succeeded\n", __FILE__, success, total); if (success == total) return 0; return 1; }
/***************************************************************************** * Test %ld format *****************************************************************************/ void UT_osprintf_ld(void) { char *test_fmt = "ld"; /* Test format character(s) */ int i; struct { char *test_num; /* Test identifier; sequential numbers */ long int test_val; /* Test value */ int max_len; /* Maximum output string length */ char *format; /* Format string */ char *expected; /* Expected result */ char *description; /* Test description */ } osp_tests[] = { {"01", 12798765, 5, "%ld", "12798765", "%ld, positive value"}, {"02", 43246372, 9, "$$$%ld$$$", "$$$43246372$$$", "%ld embedded, positive value"}, {"03", 63198765, 9, "% ld", " 63198765", "%ld with space for sign, positive value"}, {"04", 77691827, 8, "%11ld", " 77691827", "%ld with minimum field size > number of digits, positive value"}, {"05", 54691827, 5, "%4ld", "54691827", "%ld with minimum field size < number of digits, positive value"}, {"06", 77833225, 7, "%.10ld", "0077833225", "%ld with precision field size > number of digits, positive value"}, {"07", 99933225, 6, "%.3ld", "99933225", "%ld with precision field size < number of digits, positive value"}, {"08", 12345789, 8, "%12.10ld", " 0012345789", "%ld with minimum field size > precision field size > number of digits, positive value"}, {"09", 12345987, 7, "%12.3ld", " 12345987", "%ld with minimum field size > number of digits > precision field size, positive value"}, {"10", 12345444, 8, "%4.2ld", "12345444", "%ld with number of digits > minimum field size > precision field size, positive value"}, {"11", 12345321, 10, "%10.12ld", "000012345321", "%ld with precision field size > minimum field size > number of digits, positive value"}, {"12", 12333345, 9, "%6.12ld", "000012333345", "%ld with precision field size > number of digits > minimum field size, positive value"}, {"13", 12345777, 8, "%2.4ld", "12345777", "%ld with number of digits > precision field size > minimum field size, positive value"}, {"14", 98765321, 15, "%-.20ld", "00000000000098765321", "%ld with left-justify and precision field size > number of digits, positive value"}, {"15", 98765111, 8, "%-.3ld", "98765111", "%ld with left-justify and precision field size < number of digits, positive value"}, {"16", 98765222, 8, "%+ld", "+98765222", "%ld with sign, positive value"}, {"17", 46372333, 7, "$$$%+ld$$$", "$$$+46372333$$$", "%ld sign and embedded, positive value"}, {"18", 91827444, 6, "%+11ld", " +91827444", "%ld with sign and minimum field size > number of digits, positive value"}, {"19", 91827555, 5, "%+4ld", "+91827555", "%ld with sign and minimum field size < number of digits, positive value"}, {"20", 33225666, 7, "%+.13ld", "+0000033225666", "%ld with sign and precision field size > number of digits, positive value"}, {"21", 33225777, 8, "%+.3ld", "+33225777", "%ld with sign and precision field size < number of digits, positive value"}, {"22", 12345888, 9, "%+12.10ld", " +0012345888", "%ld with sign and minimum field size > precision field size > number of digits, positive value"}, {"23", 12345999, 10, "%+12.3ld", " +12345999", "%ld with sign and minimum field size > number of digits > precision field size, positive value"}, {"24", 12345000, 8, "%+4.2ld", "+12345000", "%ld with sign and number of digits > minimum field size > precision field size, positive value"}, {"25", 12345121, 9, "%+10.12ld", "+000012345121", "%ld with sign and precision field size > minimum field size > number of digits, positive value"}, {"26", 12345232, 8, "%+6.12ld", "+000012345232", "%ld with sign and precision field size > number of digits > minimum field size, positive value"}, {"27", 12345343, 6, "%+2.4ld", "+12345343", "%ld with sign and number of digits > precision field size > minimum field size, positive value"}, {"28", 98765454, 19, "%+-.20ld", "+00000000000098765454", "%ld with sign and left-justify and precision field size > number of digits, positive value"}, {"29", 98765565, 7, "%+-.3ld", "+98765565", "%ld with sign and left-justify and precision field size < number of digits, positive value"}, {"30", 98765676, 8, "%+ld", "+98765676", "%ld with sign, positive value"}, {"31", -98765787, 9, "%ld", "-98765787", "%ld, negative value"}, {"32", -46372898, 10, "$$$%ld$$$", "$$$-46372898$$$", "%ld embedded, negative value"}, {"33", -98765909, 9, "% ld", "-98765909", "%ld with space for sign, negative value"}, {"34", -91827121, 8, "%13ld", " -91827121", "%ld with minimum field size > number of digits, negative value"}, {"35", -91827232, 5, "%4ld", "-91827232", "%ld with minimum field size < number of digits, negative value"}, {"36", -33225343, 8, "%.13ld", "-0000033225343", "%ld with precision field size > number of digits, negative value"}, {"37", -33225454, 6, "%.3ld", "-33225454", "%ld with precision field size < number of digits, negative value"}, {"38", -12345565, 7, "%12.10ld", " -0012345565", "%ld with minimum field size > precision field size > number of digits, negative value"}, {"39", -12345676, 8, "%12.4ld", " -12345676", "%ld with minimum field size > number of digits > precision field size, negative value"}, {"40", -12345787, 9, "%4.2ld", "-12345787", "%ld with number of digits > minimum field size > precision field size, negative value"}, {"41", -12345898, 11, "%7.12ld", "-000012345898", "%ld with precision field size > minimum field size > number of digits, negative value"}, {"42", -12345909, 10, "%3.12ld", "-000012345909", "%ld with precision field size > number of digits > minimum field size, negative value"}, {"43", -12345101, 9, "%2.4ld", "-12345101", "%ld with number of digits > precision field size > minimum field size, negative value"}, {"44", -98765292, 10, "%-.20ld", "-00000000000098765292", "%ld with left-justify and precision field size > number of digits, negative value"}, {"45", -98765383, 8, "%-.3ld", "-98765383", "%ld with left-justify and precision field size < number of digits, negative value"}, {"46", -98765474, 9, "%+ld", "-98765474", "%ld with sign, negative value"}, {"47", -46372565, 8, "$$$%+ld$$$", "$$$-46372565$$$", "%ld sign and embedded, negative value"}, {"48", -91827112, 7, "%+11ld", " -91827112", "%ld with sign and minimum field size > number of digits, negative value"}, {"49", -91827223, 6, "%+4ld", "-91827223", "%ld with sign and minimum field size < number of digits, negative value"}, {"50", -33225334, 11, "%+.13ld", "-0000033225334", "%ld with sign and precision field size > number of digits, negative value"}, {"51", -33225445, 9, "%+.3ld", "-33225445", "%ld with sign and precision field size < number of digits, negative value"}, {"52", -12345556, 11, "%+12.10ld", " -0012345556", "%ld with sign and minimum field size > precision field size > number of digits, negative value"}, {"53", -12345667, 10, "%+12.3ld", " -12345667", "%ld with sign and minimum field size > number of digits > precision field size, negative value"}, {"54", -12345778, 9, "%+4.2ld", "-12345778", "%ld with sign and number of digits > minimum field size > precision field size, negative value"}, {"55", -12345889, 10, "%+7.12ld", "-000012345889", "%ld with sign and precision field size > minimum field size > number of digits, negative value"}, {"56", -12345990, 9, "%+3.12ld", "-000012345990", "%ld with sign and precision field size > number of digits > minimum field size, negative value"}, {"57", -12345221, 8, "%+2.4ld", "-12345221", "%ld with sign and number of digits > precision field size > minimum field size, negative value"}, {"58", -98765332, 7, "%+-.20ld", "-00000000000098765332", "%ld with sign and left-justify and precision field size > number of digits, negative value"}, {"59", -98765443, 6, "%+-.3ld", "-98765443", "%ld with sign and left-justify and precision field size < number of digits, negative value"}, {"60", -98765554, 5, "%+ld", "-98765554", "%ld with sign, negative value"}, {"61", 0, 6, "%ld", "0", "%ld, zero value"}, {"62", 16253409, 5, "%010ld", "0016253409", "%ld with zero padding, positive value"}, {"63", -16253409, 6, "%010ld", "-016253409", "%ld with zero padding, negative value"}, {"64", 0, 6, "%012ld", "000000000000", "%ld, with zero padding, zero value"}, {"", 0, 0, "", "", ""} /* End with a null format to terminate list */ }; for (i = 0; osp_tests[i].format[0] != '\0'; i++) { /* Perform sprintf test */ init_test(); sprintf(strg_buf, osp_tests[i].format, osp_tests[i].test_val); UT_Report(check_test(osp_tests[i].expected, strg_buf), "SPRINTF", osp_tests[i].description, test_fmt, osp_tests[i].test_num); /* Truncate expected string in preparation for snprintf test */ strcpy(trunc_buf, osp_tests[i].expected); if (strlen(trunc_buf) >= osp_tests[i].max_len) { trunc_buf[osp_tests[i].max_len - 1] = '\0'; } /* Perform snprintf test */ init_test(); snprintf(strg_buf, osp_tests[i].max_len, osp_tests[i].format, osp_tests[i].test_val); UT_Report(check_test(trunc_buf, strg_buf), "SNPRINTF", osp_tests[i].description, test_fmt, osp_tests[i].test_num); } }
static int test_handshake(int idx) { int ret = 0; SSL_CTX *server_ctx = NULL, *server2_ctx = NULL, *client_ctx = NULL, *resume_server_ctx = NULL, *resume_client_ctx = NULL; SSL_TEST_CTX *test_ctx = NULL; HANDSHAKE_RESULT *result = NULL; char test_app[MAX_TESTCASE_NAME_LENGTH]; BIO_snprintf(test_app, sizeof(test_app), "test-%d", idx); test_ctx = SSL_TEST_CTX_create(conf, test_app); if (test_ctx == NULL) goto err; #ifndef OPENSSL_NO_DTLS if (test_ctx->method == SSL_TEST_METHOD_DTLS) { server_ctx = SSL_CTX_new(DTLS_server_method()); if (test_ctx->extra.server.servername_callback != SSL_TEST_SERVERNAME_CB_NONE) { server2_ctx = SSL_CTX_new(DTLS_server_method()); TEST_check(server2_ctx != NULL); } client_ctx = SSL_CTX_new(DTLS_client_method()); if (test_ctx->handshake_mode == SSL_TEST_HANDSHAKE_RESUME) { resume_server_ctx = SSL_CTX_new(DTLS_server_method()); resume_client_ctx = SSL_CTX_new(DTLS_client_method()); TEST_check(resume_server_ctx != NULL); TEST_check(resume_client_ctx != NULL); } } #endif if (test_ctx->method == SSL_TEST_METHOD_TLS) { server_ctx = SSL_CTX_new(TLS_server_method()); /* SNI on resumption isn't supported/tested yet. */ if (test_ctx->extra.server.servername_callback != SSL_TEST_SERVERNAME_CB_NONE) { server2_ctx = SSL_CTX_new(TLS_server_method()); TEST_check(server2_ctx != NULL); } client_ctx = SSL_CTX_new(TLS_client_method()); if (test_ctx->handshake_mode == SSL_TEST_HANDSHAKE_RESUME) { resume_server_ctx = SSL_CTX_new(TLS_server_method()); resume_client_ctx = SSL_CTX_new(TLS_client_method()); TEST_check(resume_server_ctx != NULL); TEST_check(resume_client_ctx != NULL); } } TEST_check(server_ctx != NULL); TEST_check(client_ctx != NULL); TEST_check(CONF_modules_load(conf, test_app, 0) > 0); if (!SSL_CTX_config(server_ctx, "server") || !SSL_CTX_config(client_ctx, "client")) { goto err; } if (server2_ctx != NULL && !SSL_CTX_config(server2_ctx, "server2")) goto err; if (resume_server_ctx != NULL && !SSL_CTX_config(resume_server_ctx, "resume-server")) goto err; if (resume_client_ctx != NULL && !SSL_CTX_config(resume_client_ctx, "resume-client")) goto err; result = do_handshake(server_ctx, server2_ctx, client_ctx, resume_server_ctx, resume_client_ctx, test_ctx); ret = check_test(result, test_ctx); err: CONF_modules_unload(0); SSL_CTX_free(server_ctx); SSL_CTX_free(server2_ctx); SSL_CTX_free(client_ctx); SSL_CTX_free(resume_server_ctx); SSL_CTX_free(resume_client_ctx); SSL_TEST_CTX_free(test_ctx); HANDSHAKE_RESULT_free(result); return ret; }