another directory rename: failstar -> fail
"failstar" sounds like a name for a cruise liner from the 80s. As "*" isn't a desirable part of directory names, just name the whole thing "fail/", the core parts being stored in "fail/core/". Additionally fixing two build system dependency issues: - missing jobserver -> protomessages dependency - broken bochs -> fail dependency (add_custom_target DEPENDS only allows plain file dependencies ... cmake for the win) git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@956 8c4709b5-6ec9-48aa-a5cd-a96041d1645a
This commit is contained in:
34
core/tests/CMakeLists.txt
Normal file
34
core/tests/CMakeLists.txt
Normal file
@ -0,0 +1,34 @@
|
||||
## Setup desired protobuf descriptions HERE ##
|
||||
#set(MY_PROTOS
|
||||
# TestData.proto
|
||||
#)
|
||||
|
||||
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
|
||||
|
||||
#find_package (LibElf REQUIRED)
|
||||
#find_package (LibDwarf REQUIRED)
|
||||
|
||||
#### PROTOBUFS ####
|
||||
#find_package(Protobuf REQUIRED)
|
||||
#include_directories(${PROTOBUF_INCLUDE_DIRS})
|
||||
include_directories(${CMAKE_BINARY_DIR})
|
||||
include_directories(${CMAKE_CURERNT_BINARY_DIR})
|
||||
|
||||
#PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS ${MY_PROTOS} )
|
||||
|
||||
## Build library
|
||||
#add_library(testmessages ${PROTO_SRCS})
|
||||
|
||||
## Add some tests
|
||||
#add_executable(testclient client.cc )
|
||||
#add_executable(testclient testjc.cc )
|
||||
#add_executable(testserver server.cc)
|
||||
#target_link_libraries(testclient fail ${PROTOBUF_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} anexperimentmessage protomessages)
|
||||
#target_link_libraries(testserver fail ${PROTOBUF_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} anexperimentmessage protomessages)
|
||||
|
||||
|
||||
#add_executable(dwarf dwarf.cc)
|
||||
#target_link_libraries(dwarf ${LIBDWARF_LIBRARIES} ${LIBELF_LIBRARIES} )
|
||||
#include_directories(${CMAKE_BINARY_DIR}/core/experiments/MHTestCampaign)
|
||||
#add_executable(mhcampaign mhcampaign.cc)
|
||||
#target_link_libraries(mhcampaign mhtestcampaign fail ${PROTOBUF_LIBRARY} ${Boost_THREAD_LIBRARY})
|
||||
6
core/tests/TestData.proto
Normal file
6
core/tests/TestData.proto
Normal file
@ -0,0 +1,6 @@
|
||||
message TestData {
|
||||
optional string foo = 1;
|
||||
optional int64 input = 2;
|
||||
|
||||
optional int64 output = 3;
|
||||
}
|
||||
110
core/tests/client.cc
Normal file
110
core/tests/client.cc
Normal file
@ -0,0 +1,110 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "jobserver/messagedefs/FailControlMessage.pb.h"
|
||||
#include "jobserver/SocketComm.hpp"
|
||||
|
||||
#include "experiments/AnExperiment/AnExperiment.pb.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void error(const char *s)
|
||||
{
|
||||
perror(s);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
template <typename Message>
|
||||
Message *get_job(int sockfd)
|
||||
{
|
||||
Message *msg = new Message;
|
||||
FailControlMessage ctrlmsg;
|
||||
|
||||
ctrlmsg.set_command(FailControlMessage_Command_NEED_WORK);
|
||||
ctrlmsg.set_build_id(42);
|
||||
|
||||
cout << "Sending need work msg: " << ctrlmsg.build_id() << ", Command: " << ctrlmsg.command() << endl;
|
||||
fi::SocketComm::send_msg(sockfd, ctrlmsg);
|
||||
cout << "sent ctrl message." << endl;
|
||||
fi::SocketComm::rcv_msg(sockfd, ctrlmsg);
|
||||
cout << "Received ctrl message: " << ctrlmsg.command() << endl;
|
||||
switch(ctrlmsg.command()){
|
||||
case FailControlMessage_Command_DIE: return 0;
|
||||
case FailControlMessage_Command_WORK_FOLLOWS:
|
||||
fi::SocketComm::rcv_msg(sockfd, *msg);
|
||||
return msg;
|
||||
default:
|
||||
cerr << "wtf?" << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename Message>
|
||||
void return_result(int sockfd, Message *msg)
|
||||
{
|
||||
FailControlMessage ctrlmsg;
|
||||
|
||||
ctrlmsg.set_command(FailControlMessage_Command_RESULT_FOLLOWS);
|
||||
ctrlmsg.set_build_id(42);
|
||||
cout << "Sending Result msg: " << ctrlmsg.build_id() << ", Command: " << ctrlmsg.command() << endl;
|
||||
fi::SocketComm::send_msg(sockfd, ctrlmsg);
|
||||
fi::SocketComm::send_msg(sockfd, *msg);
|
||||
delete msg;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv){
|
||||
int portno;
|
||||
struct hostent *server;
|
||||
|
||||
cout << "JobClient" << endl;
|
||||
|
||||
if (argc < 3) {
|
||||
cerr << "usage: " << argv[0] << " hostname port" << endl;
|
||||
return 1;
|
||||
}
|
||||
portno = atoi(argv[2]);
|
||||
server = gethostbyname(argv[1]);
|
||||
if (server == NULL) {
|
||||
cerr << "cannot resolve host " << argv[1] << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int i = 1;
|
||||
while (1) {
|
||||
int sockfd;
|
||||
struct sockaddr_in serv_addr;
|
||||
cout << ">>>>>>>>>Durchgang " << i++ << endl;
|
||||
sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (sockfd < 0) {
|
||||
error("socket()");
|
||||
}
|
||||
memset(&serv_addr, 0, sizeof(serv_addr));
|
||||
serv_addr.sin_family = AF_INET;
|
||||
memcpy(&serv_addr.sin_addr.s_addr, server->h_addr, server->h_length);
|
||||
serv_addr.sin_port = htons(portno);
|
||||
|
||||
if (connect(sockfd, (sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
|
||||
error("connect()");
|
||||
}
|
||||
|
||||
MHTestData *msg = get_job<MHTestData>(sockfd);
|
||||
if(!msg){
|
||||
break;
|
||||
close(sockfd);
|
||||
}
|
||||
cout << "[Minion] received job input: " << msg->input() << endl;
|
||||
cout << "[Minion] Calculating " << msg->input() << "^2 = " << msg->input() * msg->input() << endl;
|
||||
msg->set_output(msg->input() * msg->input());
|
||||
sleep(1);
|
||||
cout << "[Minion] returning result: " << msg->output() << endl;
|
||||
|
||||
return_result<MHTestData>(sockfd, msg);
|
||||
|
||||
close(sockfd);
|
||||
}
|
||||
cout << "ByeBye" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
163
core/tests/dwarf.cc
Normal file
163
core/tests/dwarf.cc
Normal file
@ -0,0 +1,163 @@
|
||||
/* Code sample: Using libdwarf for getting the address of a function
|
||||
** from DWARF in an ELF executable.
|
||||
** Not much error-handling or resource-freeing is done here...
|
||||
**
|
||||
** Eli Bendersky (http://eli.thegreenplace.net)
|
||||
** This code is in the public domain.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <dwarf.h>
|
||||
#include <libdwarf.h>
|
||||
|
||||
|
||||
void die(char* fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
/* List a function if it's in the given DIE.
|
||||
*/
|
||||
void list_func_in_die(Dwarf_Debug dgb, Dwarf_Die the_die)
|
||||
{
|
||||
char* die_name = 0;
|
||||
const char* tag_name = 0;
|
||||
Dwarf_Error err;
|
||||
Dwarf_Half tag;
|
||||
Dwarf_Attribute* attrs;
|
||||
Dwarf_Addr lowpc, highpc;
|
||||
Dwarf_Signed attrcount, i;
|
||||
int rc = dwarf_diename(the_die, &die_name, &err);
|
||||
|
||||
if (rc == DW_DLV_ERROR)
|
||||
die("Error in dwarf_diename\n");
|
||||
else if (rc == DW_DLV_NO_ENTRY)
|
||||
return;
|
||||
|
||||
if (dwarf_tag(the_die, &tag, &err) != DW_DLV_OK)
|
||||
die("Error in dwarf_tag\n");
|
||||
|
||||
/* Only interested in subprogram DIEs here */
|
||||
if (tag != DW_TAG_subprogram)
|
||||
return;
|
||||
|
||||
if (dwarf_get_TAG_name(tag, &tag_name) != DW_DLV_OK)
|
||||
die("Error in dwarf_get_TAG_name\n");
|
||||
|
||||
printf("DW_TAG_subprogram: '%s'\n", die_name);
|
||||
|
||||
/* Grab the DIEs attributes for display */
|
||||
if (dwarf_attrlist(the_die, &attrs, &attrcount, &err) != DW_DLV_OK)
|
||||
die("Error in dwarf_attlist\n");
|
||||
|
||||
for (i = 0; i < attrcount; ++i) {
|
||||
Dwarf_Half attrcode;
|
||||
if (dwarf_whatattr(attrs[i], &attrcode, &err) != DW_DLV_OK)
|
||||
die("Error in dwarf_whatattr\n");
|
||||
|
||||
/* We only take some of the attributes for display here.
|
||||
** More can be picked with appropriate tag constants.
|
||||
*/
|
||||
if (attrcode == DW_AT_low_pc)
|
||||
dwarf_formaddr(attrs[i], &lowpc, 0);
|
||||
else if (attrcode == DW_AT_high_pc)
|
||||
dwarf_formaddr(attrs[i], &highpc, 0);
|
||||
}
|
||||
|
||||
printf("low pc : 0x%08llx\n", lowpc);
|
||||
printf("high pc : 0x%08llx\n", highpc);
|
||||
}
|
||||
|
||||
|
||||
/* List all the functions from the file represented by the given descriptor.
|
||||
*/
|
||||
void list_funcs_in_file(Dwarf_Debug dbg)
|
||||
{
|
||||
Dwarf_Unsigned cu_header_length, abbrev_offset, next_cu_header;
|
||||
Dwarf_Half version_stamp, address_size;
|
||||
Dwarf_Error err;
|
||||
Dwarf_Die no_die = 0, cu_die, child_die;
|
||||
|
||||
/* Find compilation unit header */
|
||||
while (dwarf_next_cu_header(
|
||||
dbg,
|
||||
&cu_header_length,
|
||||
&version_stamp,
|
||||
&abbrev_offset,
|
||||
&address_size,
|
||||
&next_cu_header,
|
||||
&err) != DW_DLV_ERROR) {
|
||||
|
||||
/* Expect the CU to have a single sibling - a DIE */
|
||||
if (dwarf_siblingof(dbg, no_die, &cu_die, &err) == DW_DLV_ERROR)
|
||||
die("Error getting sibling of CU\n");
|
||||
|
||||
/* Expect the CU DIE to have children */
|
||||
if (dwarf_child(cu_die, &child_die, &err) == DW_DLV_ERROR)
|
||||
die("Error getting child of CU DIE\n");
|
||||
|
||||
/* Now go over all children DIEs */
|
||||
while (1) {
|
||||
int rc;
|
||||
list_func_in_die(dbg, child_die);
|
||||
|
||||
rc = dwarf_siblingof(dbg, child_die, &child_die, &err);
|
||||
|
||||
if (rc == DW_DLV_ERROR)
|
||||
die("Error getting sibling of DIE\n");
|
||||
else if (rc == DW_DLV_NO_ENTRY)
|
||||
break; /* done */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
Dwarf_Debug dbg = 0;
|
||||
Dwarf_Error err;
|
||||
const char* progname;
|
||||
int fd = -1;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "Expected a program name as argument\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
progname = argv[1];
|
||||
if ((fd = open(progname, O_RDONLY)) < 0) {
|
||||
perror("open");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (dwarf_init(fd, DW_DLC_READ, 0, 0, &dbg, &err) != DW_DLV_OK) {
|
||||
fprintf(stderr, "Failed DWARF initialization\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
list_funcs_in_file(dbg);
|
||||
|
||||
if (dwarf_finish(dbg, &err) != DW_DLV_OK) {
|
||||
fprintf(stderr, "Failed DWARF finalization\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
BIN
core/tests/main.elf
Executable file
BIN
core/tests/main.elf
Executable file
Binary file not shown.
62
core/tests/server.cc
Normal file
62
core/tests/server.cc
Normal file
@ -0,0 +1,62 @@
|
||||
#include "jobserver/JobServer.hpp"
|
||||
#include <iostream>
|
||||
#include "experiments/AnExperiment.hpp"
|
||||
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
|
||||
fi::JobServer js;
|
||||
using namespace std;
|
||||
|
||||
static const int nums = 30;
|
||||
|
||||
void exec_js(){
|
||||
js.waitForConnections();
|
||||
cout << "That's it.." << endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char**argv){
|
||||
|
||||
|
||||
cout << "Testing Jobserver" << endl;
|
||||
boost::thread th(exec_js);
|
||||
|
||||
AnExperimentData* datas[nums];
|
||||
|
||||
for(int i = 1; i <= nums; i++){
|
||||
datas[i] = new AnExperimentData;
|
||||
datas[i]->setInput(i);
|
||||
js.addExperiment(datas[i]);
|
||||
usleep(100 * 1000); // 100 ms
|
||||
}
|
||||
js.setNoMoreExperiments();
|
||||
|
||||
// test results.
|
||||
int f;
|
||||
int res = 0;
|
||||
int res2 = 0;
|
||||
AnExperimentData * exp;
|
||||
for(int i = 1; i <= nums; i++){
|
||||
exp = static_cast<AnExperimentData*>( js.m_doneJobs.Dequeue() );
|
||||
f = exp->getOutput();
|
||||
// cout << ">>>>>>>>>>>>>>> Output: " << i << "^2 = " << f << endl;
|
||||
res += f;
|
||||
res2 += (i*i);
|
||||
delete exp;
|
||||
}
|
||||
if (res == res2) {
|
||||
cout << "TEST SUCCESSFUL FINISHED! " << "[" << res << "==" << res2 << "]" << endl;
|
||||
}else{
|
||||
cout << "TEST FAILED!" << " [" << res << "!=" << res2 << "]" << endl;
|
||||
}
|
||||
cout << "thats all, waiting for server thread. " << endl;
|
||||
js.done();
|
||||
|
||||
th.join();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
42
core/tests/testjc.cc
Normal file
42
core/tests/testjc.cc
Normal file
@ -0,0 +1,42 @@
|
||||
#include <iostream>
|
||||
#include "jobserver/JobClient.hpp"
|
||||
|
||||
#include "experiments/AnExperiment.hpp"
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace fi;
|
||||
int main(int argc, char** argv){
|
||||
|
||||
int portno;
|
||||
JobClient* jc;
|
||||
cout << "JobClient" << endl;
|
||||
if(argc == 1){
|
||||
jc = new JobClient();
|
||||
}else if(argc == 3){
|
||||
portno = atoi(argv[2]);
|
||||
jc = new JobClient(argv[1], portno);
|
||||
}else{
|
||||
cerr << "usage: " << argv[0] << " hostname port" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
AnExperimentData exp;
|
||||
|
||||
while(1){
|
||||
if(jc->getExperimentData(exp)){
|
||||
/// Do some work.
|
||||
cout << "Got data: " << exp.getInput() << endl;
|
||||
int result = exp.getInput() * exp.getInput();
|
||||
usleep(500 * 1000); // 500 ms
|
||||
/// Send back.
|
||||
exp.setOutput(result);
|
||||
jc->sendResult(exp);
|
||||
}else{
|
||||
cout << "No (more) data for me :(" << endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
delete jc;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user