int main(int argc, char **argv){ bt_zero("~~~Userspace test program start!~~~\n"); print_string("TEST Command Prompt!\n"); while(true){ char input[128]={0}; print_string("[TEST]>"); get_string(input, 128); if(input[0]=='d') dir_listing(); else if(input[0]=='b') ata_test(); else if(input[0]=='l') dir_listing2(input); else if(input[0]=='f') file_contents(); else if(input[0]=='c') file_contents2(input); else if(input[0]=='m') mount_test(); else if(input[0]=='v') version(); else if(input[0]=='r') run_program(input); else if(input[0]=='p') path(input); else if(input[0]=='t') thread_test(); else if(input[0]=='x') crash_test(); else if(input[0]=='q') break; else { if(strlen(input) && input[0]!='\n') print_string("Unrecognised command.\n"); } } bt_zero("~~~Userspace test program done!~~~\n"); bt_exit(0); return 0; }
R operator()(Ps... ps){ std::stringstream pss; serialize(pss, ps...); auto data = pss.str(); int msgno = data.size() / BT_MSG_MAX; bt_msg_header msg; while(msgno >= 0){ size_t len = std::min(BT_MSG_MAX, data.size()); msg.flags = 0; msg.type = msgtype; msg.to = pid; msg.length = len; msg.source = msgno--; msg.content = (void*)data.c_str(); msg.id = bt_send(msg); if(msgno >= 0) data = data.substr(len); } bt_msg_header reply; bt_msg_filter filter; std::stringstream rss; bool more_data = true; while(more_data){ filter.flags = bt_msg_filter_flags::Reply; filter.reply_to = msg.id; reply = bt_recv_filtered(filter, true); while(reply.reply_id != msg.id){ std::stringstream ss; ss << "RPC: Spurious message!" << std::endl; ss << "Message id: " << reply.id << std::endl; ss << "From : " << reply.from << std::endl; ss << "Flags : " << reply.flags << std::endl; ss << "Reply ID: " << reply.reply_id << " (Waiting for: " << msg.id << ")" << std::endl; bt_zero(ss.str().c_str()); bt_next_msg_filtered(&reply, filter); } std::vector<char> replyData(reply.length); bt_msg_content(&reply, &replyData[0], reply.length); rss.write(&replyData[0], replyData.size()); if(reply.type == MessageType_Continue){ msg.flags = bt_msg_flags::Reply; msg.reply_id = reply.id; msg.type = MessageType_Continue; msg.to = pid; msg.length = 0; msg.content = nullptr; msg.id = bt_send(msg); more_data = true; }else{ more_data = false; } bt_msg_ack(&reply); } rss.seekg(0); R ret; deserialize(rss, ret); return ret; }
void panic(const char *msg){ bt_zero(msg); bt_exit(-1); }