adds coverage plugin

This commit is contained in:
Eyck-Alexander Jentzsch 2022-01-31 21:38:18 +01:00
parent afe8905ac9
commit 7578906310
4 changed files with 124 additions and 0 deletions

View File

@ -36,6 +36,8 @@ set(LIB_SOURCES
src/vm/fp_functions.cpp src/vm/fp_functions.cpp
src/plugin/instruction_count.cpp src/plugin/instruction_count.cpp
src/plugin/cycle_estimate.cpp src/plugin/cycle_estimate.cpp
src/plugin/cov.cpp
${TGC_SOURCES} ${TGC_SOURCES}
${TGC_VM_SOURCES} ${TGC_VM_SOURCES}
) )

84
incl/iss/plugin/cov.h Normal file
View File

@ -0,0 +1,84 @@
/*******************************************************************************
* Copyright (C) 2017, 2018, MINRES Technologies GmbH
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Contributors:
* eyck@minres.com - initial API and implementation
******************************************************************************/
#ifndef _ISS_PLUGIN_COV_H_
#define _ISS_PLUGIN_COV_H_
#include <iss/vm_plugin.h>
#include "iss/instrumentation_if.h"
#include <json/json.h>
#include <string>
#include <fstream>
namespace iss {
namespace plugin {
class cov : public iss::vm_plugin {
struct instr_delay {
std::string instr_name;
size_t size;
size_t not_taken_delay;
size_t taken_delay;
};
public:
cov(const cov &) = delete;
cov(const cov &&) = delete;
cov();
virtual ~cov();
cov &operator=(const cov &) = delete;
cov &operator=(const cov &&) = delete;
bool registration(const char *const version, vm_if &arch) override;
sync_type get_sync() override { return POST_SYNC; };
void callback(instr_info_t, exec_info const&) override;
private:
iss::instrumentation_if *instr_if {nullptr};
int counter {0};
std::ofstream output;
};
}
}
#endif /* _ISS_PLUGIN_COV_H_ */

32
src/plugin/cov.cpp Normal file
View File

@ -0,0 +1,32 @@
#include <iss/plugin/cov.h>
#include <iss/arch_if.h>
#include <iostream>
iss::plugin::cov::cov() {
std::cout << "Entering Constructor"<<std::endl;
output.open("output.txt");
}
iss::plugin::cov::~cov() {
std::cout << "Entering Destructor"<<std::endl;
output.close();
}
bool iss::plugin::cov::registration(const char *const version, vm_if& vm) {
instr_if = vm.get_arch()->get_instrumentation_if();
return true;
}
void iss::plugin::cov::callback(instr_info_t iinfo, const exec_info&) {
// if((instr_if->get_next_pc() - instr_if->get_pc() != 4) ||( instr_if->get_next_pc() - instr_if->get_pc() != 2)){
// std::cout << "jump from " << std::hex << instr_if->get_pc() << " to " << instr_if->get_next_pc()<< " after " << std::dec << counter <<" linear instructions" <<std::endl;
// counter = 0;
// }else {
// counter++;
// }
output<<std::hex << instr_if->get_pc() << std::endl;
}

View File

@ -69,6 +69,8 @@ using tgc_d_xrb_nn_plat_type = iss::arch::riscv_hart_mu_p<iss::arch::tgc_d_xrb_n
#include <array> #include <array>
#include <iss/plugin/cycle_estimate.h> #include <iss/plugin/cycle_estimate.h>
#include <iss/plugin/instruction_count.h> #include <iss/plugin/instruction_count.h>
#include <iss/plugin/cov.h>
// clang-format on // clang-format on
#define STR(X) #X #define STR(X) #X
@ -423,6 +425,10 @@ void core_complex::before_end_of_elaboration() {
auto *plugin = new iss::plugin::cycle_estimate(filename); auto *plugin = new iss::plugin::cycle_estimate(filename);
cpu->vm->register_plugin(*plugin); cpu->vm->register_plugin(*plugin);
plugin_list.push_back(plugin); plugin_list.push_back(plugin);
} else if (plugin_name == "cov") {
auto *plugin = new iss::plugin::cov();
cpu->vm->register_plugin(*plugin);
plugin_list.push_back(plugin);
} else { } else {
std::array<char const*, 1> a{{filename.c_str()}}; std::array<char const*, 1> a{{filename.c_str()}};
iss::plugin::loader l(plugin_name, {{"initPlugin"}}); iss::plugin::loader l(plugin_name, {{"initPlugin"}});