Home | History | Annotate | Download | only in tests
      1 /**
      2  * @file abi_test.cpp
      3  * Import sample files from other ABI
      4  *
      5  * @remark Copyright 2002 OProfile authors
      6  * @remark Read the file COPYING
      7  *
      8  * @author Graydon Hoare
      9  */
     10 
     11 #include "abi.h"
     12 #include "odb.h"
     13 #include "popt_options.h"
     14 #include "op_sample_file.h"
     15 #include "op_cpu_type.h"
     16 #include "op_config.h"
     17 
     18 #include <fstream>
     19 #include <iostream>
     20 
     21 #include <cstdlib>
     22 #include <cstring>
     23 
     24 using namespace std;
     25 
     26 namespace {
     27 	string db_filename;
     28 	string abi_filename;
     29 }
     30 
     31 
     32 popt::option options_array[] = {
     33 	popt::option(db_filename, "db", 'd', "output db to file", "filename"),
     34 	popt::option(abi_filename, "abi", 'a', "output abi to file", "filename")
     35 };
     36 
     37 
     38 int main(int argc, char const ** argv)
     39 {
     40 	vector<string> rest;
     41 	popt::parse_options(argc, argv, rest);
     42 
     43 	if (abi_filename.empty() && db_filename.empty()) {
     44 		cerr << "error: no file specified to work on" << endl;
     45 		exit(1);
     46 	}
     47 
     48 
     49 	if (!abi_filename.empty()) {
     50 		ofstream file(abi_filename.c_str());
     51 		if (!file) {
     52 			cerr << "error: cannot open " << abi_filename
     53 			     << " for writing" << endl;
     54 			exit(1);
     55 		}
     56 		file << abi();
     57 	}
     58 
     59 	if (!db_filename.empty()) {
     60 		odb_t dest;
     61 		int rc = odb_open(&dest, db_filename.c_str(), ODB_RDWR,
     62 		                  sizeof(struct opd_header));
     63 
     64 		if (rc) {
     65 			cerr << "odb_open() fail:\n"
     66 			     << strerror(rc) << endl;
     67 			exit(EXIT_FAILURE);
     68 		}
     69 
     70 		struct opd_header * header;
     71 		header = static_cast<struct opd_header *>(odb_get_data(&dest));
     72 		memset(header, '\0', sizeof(struct opd_header));
     73 		header->version = OPD_VERSION;
     74 		memcpy(header->magic, OPD_MAGIC, sizeof(header->magic));
     75 		header->is_kernel = 1;
     76 		/* ICACHE_FETCHES */
     77 		header->ctr_event = 0x80;
     78 		header->ctr_um = 0x0;
     79 		header->cpu_type = CPU_ATHLON;
     80 		header->ctr_count = 0xdeadbeef;
     81 		header->cpu_speed = 0;
     82 		header->mtime = 1034790063;
     83 		header->cg_to_is_kernel = 1;
     84 		header->anon_start = 0;
     85 		header->cg_to_anon_start = 0;
     86 
     87 		for (int i = 0; i < 3793; ++i) {
     88 			int rc = odb_add_node(&dest, i, i);
     89 			if (rc != EXIT_SUCCESS) {
     90 				cerr << strerror(rc) << endl;
     91 				exit(EXIT_FAILURE);
     92 			}
     93 		}
     94 		odb_close(&dest);
     95 	}
     96 }
     97