/* * out_get_uuid_str -- returns uuid in human readable format */ const char * out_get_uuid_str(uuid_t uuid) { static char uuid_str[UUID_STR_MAX] = {0, }; int ret = util_uuid_to_string(uuid, uuid_str); if (ret != 0) { outv(2, "failed to covert uuid to string"); return NULL; } return uuid_str; }
/* * pmempool_info_poolset -- (internal) print info about poolset structure */ static int pmempool_info_poolset(struct pmem_info *pip, int v) { ASSERTeq(pip->params.is_poolset, 1); outv(v, "Poolset structure:\n"); outv_field(v, "Number of replicas", "%u", pip->pfile->poolset->nreplicas); for (unsigned r = 0; r < pip->pfile->poolset->nreplicas; ++r) { if (pmempool_info_replica(pip, r, v)) return -1; } return 0; }
/* * pmempool_info_replica -- (internal) print info about replica */ static int pmempool_info_replica(struct pmem_info *pip, unsigned repn, int v) { struct pool_replica *rep = pip->pfile->poolset->replica[repn]; outv(v, "Replica %u%s - %s", repn, repn == 0 ? " (master)" : "", rep->remote == NULL ? "local" : "remote"); if (rep->remote) { outv(v, ":\n"); outv_field(v, "node", "%s", rep->remote->node_addr); outv_field(v, "pool set", "%s", rep->remote->pool_desc); return 0; } outv(v, ", %u part(s):\n", rep->nparts); for (unsigned p = 0; p < rep->nparts; ++p) { if (pmempool_info_part(pip, repn, p, v)) return -1; } return 0; }
/* * pmempool_info_pool_hdr -- print pool header information */ static int pmempool_info_pool_hdr(struct pmem_info *pip, int v) { int ret = 0; struct pool_hdr *hdr = malloc(sizeof (struct pool_hdr)); if (!hdr) err(1, "Cannot allocate memory for pool_hdr"); if (pmempool_info_read(pip, hdr, sizeof (*hdr), 0)) { outv_err("cannot read pool header\n"); free(hdr); return -1; } outv(v, "POOL Header:\n"); outv_hexdump(pip->args.vhdrdump, hdr, sizeof (*hdr), 0, 1); util_convert2h_pool_hdr(hdr); outv_field(v, "Signature", "%.*s%s", POOL_HDR_SIG_LEN, hdr->signature, pip->params.is_part ? " [part file]" : ""); outv_field(v, "Major", "%d", hdr->major); outv_field(v, "Mandatory features", "0x%x", hdr->incompat_features); outv_field(v, "Not mandatory features", "0x%x", hdr->compat_features); outv_field(v, "Forced RO", "0x%x", hdr->ro_compat_features); outv_field(v, "Pool set UUID", "%s", out_get_uuid_str(hdr->poolset_uuid)); outv_field(v, "UUID", "%s", out_get_uuid_str(hdr->uuid)); outv_field(v, "Previous part UUID", "%s", out_get_uuid_str(hdr->prev_part_uuid)); outv_field(v, "Next part UUID", "%s", out_get_uuid_str(hdr->next_part_uuid)); outv_field(v, "Previous replica UUID", "%s", out_get_uuid_str(hdr->prev_repl_uuid)); outv_field(v, "Next replica UUID", "%s", out_get_uuid_str(hdr->next_repl_uuid)); outv_field(v, "Creation Time", "%s", out_get_time_str((time_t)hdr->crtime)); outv_field(v, "Checksum", "%s", out_get_checksum(hdr, sizeof (*hdr), &hdr->checksum)); free(hdr); return ret; }
static int rm_poolset_cb(const char *part_file, void *arg) { outv(2, "part file : %s\n", part_file); int exists = access(part_file, F_OK) == 0; if (!exists) { /* * Ignore not accessible file if force * flag is set */ if (force) return 0; err(1, "cannot remove file '%s'", part_file); } rm_file(part_file); return 0; }
/** * @test Pass an attribute with struct type data. */ TEST_F(DeploymentTest, StructAttributeDeployment) { CommonAPI::CallStatus callStatus; { v1_0::commonapi::someip::deploymenttest::TestInterface::tStruct_wd outv(true, 100); v1_0::commonapi::someip::deploymenttest::TestInterface::tStruct_wd inv; testProxy_->getAStruct_wd_attrAttribute().setValue(outv, callStatus, inv); ASSERT_EQ(callStatus, CommonAPI::CallStatus::SUCCESS); EXPECT_EQ(outv, inv); } { v1_0::commonapi::someip::deploymenttest::TestInterface::tStruct_long outv; v1_0::commonapi::someip::deploymenttest::TestInterface::tStruct_long inv; outv.setBooleanMember(true); std::vector<int8_t> a(200); outv.setArrayMember(a); testProxy_->getAStruct_longAttribute().setValue(outv, callStatus, inv); ASSERT_EQ(callStatus, CommonAPI::CallStatus::SUCCESS); EXPECT_EQ(outv, inv); } }
/* * rm_file -- remove single file */ static void rm_file(const char *file) { int write_protected = access(file, W_OK) != 0; char cask = 'y'; switch (ask_mode) { case ASK_ALWAYS: cask = '?'; break; case ASK_NEVER: cask = 'y'; break; case ASK_SOMETIMES: cask = write_protected ? '?' : 'y'; break; } const char *pre_msg = write_protected ? "write-protected " : ""; if (ask_Yn(cask, "remove %sfile '%s' ?", pre_msg, file) == 'y') { if (util_unlink(file)) err(1, "cannot remove file '%s'", file); outv(1, "removed '%s'\n", file); } }
/* * pmempool_info_pool_hdr -- print pool header information */ static int pmempool_info_pool_hdr(struct pmem_info *pip, int v) { static const char *alignment_desc_str[] = { " char", " short", " int", " long", " long long", " size_t", " off_t", " float", " double", " long double", " void *", }; static const size_t alignment_desc_n = sizeof(alignment_desc_str) / sizeof(alignment_desc_str[0]); int ret = 0; struct pool_hdr *hdr = malloc(sizeof(struct pool_hdr)); if (!hdr) err(1, "Cannot allocate memory for pool_hdr"); if (pmempool_info_read(pip, hdr, sizeof(*hdr), 0)) { outv_err("cannot read pool header\n"); free(hdr); return -1; } struct arch_flags arch_flags; if (util_get_arch_flags(&arch_flags)) { outv_err("cannot read architecture flags\n"); free(hdr); return -1; } outv(v, "POOL Header:\n"); outv_hexdump(pip->args.vhdrdump, hdr, sizeof(*hdr), 0, 1); util_convert2h_pool_hdr(hdr); outv_field(v, "Signature", "%.*s%s", POOL_HDR_SIG_LEN, hdr->signature, pip->params.is_part ? " [part file]" : ""); outv_field(v, "Major", "%d", hdr->major); outv_field(v, "Mandatory features", "0x%x", hdr->incompat_features); outv_field(v, "Not mandatory features", "0x%x", hdr->compat_features); outv_field(v, "Forced RO", "0x%x", hdr->ro_compat_features); outv_field(v, "Pool set UUID", "%s", out_get_uuid_str(hdr->poolset_uuid)); outv_field(v, "UUID", "%s", out_get_uuid_str(hdr->uuid)); outv_field(v, "Previous part UUID", "%s", out_get_uuid_str(hdr->prev_part_uuid)); outv_field(v, "Next part UUID", "%s", out_get_uuid_str(hdr->next_part_uuid)); outv_field(v, "Previous replica UUID", "%s", out_get_uuid_str(hdr->prev_repl_uuid)); outv_field(v, "Next replica UUID", "%s", out_get_uuid_str(hdr->next_repl_uuid)); outv_field(v, "Creation Time", "%s", out_get_time_str((time_t)hdr->crtime)); uint64_t ad = hdr->arch_flags.alignment_desc; uint64_t cur_ad = arch_flags.alignment_desc; outv_field(v, "Alignment Descriptor", "%s", out_get_alignment_desc_str(ad, cur_ad)); for (size_t i = 0; i < alignment_desc_n; i++) { uint64_t a = GET_ALIGNMENT(ad, i); if (ad == cur_ad) { outv_field(v + 1, alignment_desc_str[i], "%2d", a); } else { uint64_t av = GET_ALIGNMENT(cur_ad, i); if (a == av) { outv_field(v + 1, alignment_desc_str[i], "%2d [OK]", a); } else { outv_field(v + 1, alignment_desc_str[i], "%2d [wrong! should be %2d]", a, av); } } } outv_field(v, "Class", "%s", out_get_ei_class_str(hdr->arch_flags.ei_class)); outv_field(v, "Data", "%s", out_get_ei_data_str(hdr->arch_flags.ei_data)); outv_field(v, "Machine", "%s", out_get_e_machine_str(hdr->arch_flags.e_machine)); outv_field(v, "Checksum", "%s", out_get_checksum(hdr, sizeof(*hdr), &hdr->checksum)); free(hdr); return ret; }
void SoftDemapper::Run() { unsigned int nbits,nsymbs,count; /// fetch data objects gsl_vector_complex_class input = vin1.GetDataObj(); // number of input symbs nsymbs = input.vec->size; // cout << "received " << nsymbs << " elements in vector." << endl; // number of output symbols nbits = nsymbs * Nb(); gsl_vector *llr=gsl_vector_alloc(nbits); double *den = (double *)calloc( Nb(), sizeof(double) ); double *num = (double *)calloc( Nb(), sizeof(double) ); // determine symb_likelyhood for (int i=0;i<nsymbs;i++) { // cycle through received symbols for (int k=0;k<Nb();k++) { num[k] = GSL_NEGINF; den[k] = GSL_NEGINF; } // the received symbol gsl_complex recsym = gsl_vector_complex_get(input.vec,i); // cout << "received symbol = (" // << GSL_REAL(recsym) // << "," // << GSL_IMAG(recsym) // << ") " << endl; for (int j=0;j<Ns;j++) { // cycle through postulated symbol // gray encoded symbol id unsigned int symbol_id = gsl_vector_uint_get(gray_encoding,j); // complex symbol gsl_complex refsym = gsl_complex_polar(1.0,symbol_arg * symbol_id ); // likelyhood metric double metric = gsl_complex_abs( gsl_complex_sub(refsym,recsym) ); metric = -EsNo()*metric*metric; //gsl_matrix_complex_set(symb_likelihoods,j,i); // // HERE is available a metric for symb i and refsymb j // int mask = 1 << Nb() - 1; for (int k=0;k<Nb();k++) { /* loop over bits */ if (mask&j) { /* this bit is a one */ num[k] = ( *max_star[LMAP()] )( num[k], metric ); } else { /* this bit is a zero */ den[k] = ( *max_star[LMAP()] )( den[k], metric ); } mask = mask >> 1; } //bits } // alphabet for (int k=0;k<Nb();k++) { gsl_vector_set(llr,Nb()*i+k,num[k] - den[k]); } } // symbols gsl_vector_class outv(llr); // outv.show(); // output bitwise LLR vout1.DeliverDataObj(outv); gsl_vector_free(llr); // free dynamic structures free(num); free(den); }
/* * pmempool_rm_func -- main function for rm command */ int pmempool_rm_func(char *appname, int argc, char *argv[]) { int opt; while ((opt = getopt_long(argc, argv, optstr, long_options, NULL)) != -1) { switch (opt) { case 'h': pmempool_rm_help(appname); return 0; case 'v': vlevel++; break; case 's': only_pools = 1; break; case 'f': force = 1; ask_mode = ASK_NEVER; break; case 'i': ask_mode = ASK_ALWAYS; break; default: print_usage(appname); return -1; } } out_set_vlevel(vlevel); if (optind == argc) { print_usage(appname); return -1; } for (int i = optind; i < argc; i++) { char *file = argv[i]; /* check if file exists and we can read it */ int exists = access(file, F_OK | R_OK) == 0; if (!exists) { /* ignore not accessible file if force flag is set */ if (force) continue; err(1, "cannot remove '%s'", file); } int is_poolset = util_is_poolset_file(file) == 1; if (is_poolset) outv(2, "poolset file: %s\n", file); else outv(2, "pool file : %s\n", file); if (is_poolset) { rm_poolset(file); if (!only_pools) rm_file(file); } else { rm_file(file); } } return 0; }
/* * remove_remote -- (internal) remove remote pool */ static int remove_remote(const char *target, const char *pool_set) { #ifdef USE_RPMEM char cask = 'y'; switch (ask_mode) { case ASK_ALWAYS: cask = '?'; break; case ASK_NEVER: case ASK_SOMETIMES: cask = 'y'; break; } if (ask_Yn(cask, "remove remote pool '%s' on '%s'?", pool_set, target) != 'y') return 0; struct rpmem_target_info *info = rpmem_target_parse(target); if (!info) goto err_parse; struct rpmem_ssh *ssh; if (force) { ssh = rpmem_ssh_exec(info, "--remove", pool_set, "--force", NULL); } else { ssh = rpmem_ssh_exec(info, "--remove", pool_set, NULL); } if (!ssh) goto err_ssh_exec; int ret = 0; if (rpmem_ssh_monitor(ssh, 0)) ret = 1; if (rpmem_ssh_close(ssh)) ret = 1; if (ret) goto err_ssh_exec; rpmem_target_free(info); outv(1, "removed '%s' on '%s'\n", pool_set, target); return ret; err_ssh_exec: rpmem_target_free(info); err_parse: if (!force) outv_err("cannot remove '%s' on '%s'", pool_set, target); return 1; #else outv_err("remote replication not supported"); return 1; #endif }
/** * @test Verify that the API for struct deployments works */ TEST_F(DeploymentTest, StructWithDeployment) { CommonAPI::SomeIP::Message message; CommonAPI::SomeIP::StructDeployment< CommonAPI::EmptyDeployment, CommonAPI::SomeIP::IntegerDeployment<uint8_t> > ed_0(0, nullptr, nullptr); CommonAPI::SomeIP::StructDeployment< CommonAPI::EmptyDeployment, CommonAPI::SomeIP::IntegerDeployment<uint8_t> > ed_1(1, nullptr, nullptr); CommonAPI::SomeIP::StructDeployment< CommonAPI::EmptyDeployment, CommonAPI::SomeIP::IntegerDeployment<uint8_t> > ed_2(2, nullptr, nullptr); CommonAPI::SomeIP::StructDeployment< CommonAPI::EmptyDeployment, CommonAPI::SomeIP::IntegerDeployment<uint8_t> > ed_4(4, nullptr, nullptr); message = CommonAPI::SomeIP::Message::createMethodCall( CommonAPI::SomeIP::Address(0, 0, 0, 0), 515, false); { CommonAPI::SomeIP::OutputStream outStream(message, false); v1_0::commonapi::someip::deploymenttest::TestInterface::tStruct_w4 outv(true, 100); outStream.writeValue(outv, &ed_0); EXPECT_FALSE(outStream.hasError()); outStream.flush(); CommonAPI::SomeIP::InputStream inStream(message, false); v1_0::commonapi::someip::deploymenttest::TestInterface::tStruct_w4 inv; inStream.readValue(inv, &ed_0); EXPECT_FALSE(inStream.hasError()); EXPECT_EQ(outv, inv); } { CommonAPI::SomeIP::OutputStream outStream(message, false); v1_0::commonapi::someip::deploymenttest::TestInterface::tStruct_w4 outv(true, 100); outStream.writeValue(outv, &ed_1); EXPECT_FALSE(outStream.hasError()); outStream.flush(); CommonAPI::SomeIP::InputStream inStream(message, false); v1_0::commonapi::someip::deploymenttest::TestInterface::tStruct_w4 inv; inStream.readValue(inv, &ed_1); EXPECT_FALSE(inStream.hasError()); EXPECT_EQ(outv, inv); } { CommonAPI::SomeIP::OutputStream outStream(message, false); v1_0::commonapi::someip::deploymenttest::TestInterface::tStruct_w4 outv(true, 100); outStream.writeValue(outv, &ed_2); EXPECT_FALSE(outStream.hasError()); outStream.flush(); CommonAPI::SomeIP::InputStream inStream(message, false); v1_0::commonapi::someip::deploymenttest::TestInterface::tStruct_w4 inv; inStream.readValue(inv, &ed_2); EXPECT_FALSE(inStream.hasError()); EXPECT_EQ(outv, inv); } { CommonAPI::SomeIP::OutputStream outStream(message, false); v1_0::commonapi::someip::deploymenttest::TestInterface::tStruct_w4 outv(true, 100); outStream.writeValue(outv, &ed_4); EXPECT_FALSE(outStream.hasError()); outStream.flush(); CommonAPI::SomeIP::InputStream inStream(message, false); v1_0::commonapi::someip::deploymenttest::TestInterface::tStruct_w4 inv; inStream.readValue(inv, &ed_4); EXPECT_FALSE(inStream.hasError()); EXPECT_EQ(outv, inv); } }
/** * @test Stream some struct data with various deployments. */ TEST_F(DeploymentTest, StructWithOutputDeployment) { CommonAPI::SomeIP::Message message; message = CommonAPI::SomeIP::Message::createMethodCall( CommonAPI::SomeIP::Address(0, 0, 0, 0), 515, false); { CommonAPI::SomeIP::StructDeployment< CommonAPI::EmptyDeployment, CommonAPI::SomeIP::IntegerDeployment<uint8_t> > ed(4, nullptr, nullptr); CommonAPI::SomeIP::OutputStream outStream(message, false); CommonAPI::SomeIP::byte_t expected_data[] = { 0, 0, 0, 2, /* = length of data in bytes - four bytes specified in the deployment */ 1, /* true */ 100 /* 100 */ }; v1_0::commonapi::someip::deploymenttest::TestInterface::tStruct_w4 outv(true, 100); outStream.writeValue(outv, &ed); EXPECT_FALSE(outStream.hasError()); outStream.flush(); CommonAPI::SomeIP::byte_t * data = message.getBodyData(); CommonAPI::SomeIP::message_length_t length = message.getBodyLength(); ASSERT_EQ(sizeof expected_data, length); for (unsigned int i = 0; i < length; i++) { EXPECT_EQ(expected_data[i], data[i]); } } { CommonAPI::SomeIP::StructDeployment< CommonAPI::EmptyDeployment, CommonAPI::SomeIP::IntegerDeployment<uint8_t> > ed(2, nullptr, nullptr); CommonAPI::SomeIP::OutputStream outStream(message, false); CommonAPI::SomeIP::byte_t expected_data[] = { 0, 2, /* = length of data in bytes - two bytes specified in the deployment */ 1, /* true */ 100 /* 100 */ }; v1_0::commonapi::someip::deploymenttest::TestInterface::tStruct_w4 outv(true, 100); outStream.writeValue(outv, &ed); EXPECT_FALSE(outStream.hasError()); outStream.flush(); CommonAPI::SomeIP::byte_t * data = message.getBodyData(); CommonAPI::SomeIP::message_length_t length = message.getBodyLength(); ASSERT_EQ(sizeof expected_data, length); for (unsigned int i = 0; i < length; i++) { EXPECT_EQ(expected_data[i], data[i]); } } { CommonAPI::SomeIP::StructDeployment< CommonAPI::EmptyDeployment, CommonAPI::SomeIP::IntegerDeployment<uint8_t> > ed(1, nullptr, nullptr); CommonAPI::SomeIP::OutputStream outStream(message, false); CommonAPI::SomeIP::byte_t expected_data[] = { 2, /* = length of data in bytes - one byte specified in the deployment */ 1, /* true */ 100 /* 100 */ }; v1_0::commonapi::someip::deploymenttest::TestInterface::tStruct_w4 outv(true, 100); outStream.writeValue(outv, &ed); EXPECT_FALSE(outStream.hasError()); outStream.flush(); CommonAPI::SomeIP::byte_t * data = message.getBodyData(); CommonAPI::SomeIP::message_length_t length = message.getBodyLength(); ASSERT_EQ(sizeof expected_data, length); for (unsigned int i = 0; i < length; i++) { EXPECT_EQ(expected_data[i], data[i]); } } { CommonAPI::SomeIP::StructDeployment< CommonAPI::EmptyDeployment, CommonAPI::SomeIP::IntegerDeployment<uint8_t> > ed(0, nullptr, nullptr); CommonAPI::SomeIP::OutputStream outStream(message, false); CommonAPI::SomeIP::byte_t expected_data[] = { 1, /* true */ 100 /* 100 */ }; v1_0::commonapi::someip::deploymenttest::TestInterface::tStruct_w4 outv(true, 100); outStream.writeValue(outv, &ed); EXPECT_FALSE(outStream.hasError()); outStream.flush(); CommonAPI::SomeIP::byte_t * data = message.getBodyData(); CommonAPI::SomeIP::message_length_t length = message.getBodyLength(); ASSERT_EQ(sizeof expected_data, length); for (unsigned int i = 0; i < length; i++) { EXPECT_EQ(expected_data[i], data[i]); } } }