Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 728dfb79 authored by Nicolas Carion's avatar Nicolas Carion

improve fuzzing and logging

parent 299a0f99
......@@ -261,11 +261,22 @@ void fuzz(const std::string &input)
while (ss >> c) {
if (Logger::back_translation_table.count(c) > 0) {
// std::cout << "found=" << c;
std::cout << "found=" << c;
c = Logger::back_translation_table[c];
// std::cout << " tranlated=" << c << std::endl;
if (c == "constr_TimelineModel") {
all_timelines.emplace_back(TimelineItemModel::construct(&profile, guideModel, undoStack));
} else if (c == "constr_ClipModel") {
auto timeline = get_timeline();
int id = 0, state_id;
double speed = 1;
PlaylistState::ClipState state = PlaylistState::VideoOnly;
std::string binId;
ss >> binId >> id >> state_id >> speed;
state = static_cast<PlaylistState::ClipState>(state_id);
if (timeline) {
ClipModel::construct(timeline, QString::fromStdString(binId), -1, state, speed);
}
} else if (c == "constr_TrackModel") {
auto timeline = get_timeline();
int id, pos = 0;
......@@ -289,12 +300,12 @@ void fuzz(const std::string &input)
} else if (c == "constr_test_producer_sound") {
createProducerWithSound(profile, binModel);
} else {
// std::cout << "executing " << c << std::endl;
std::cout << "executing " << c << std::endl;
rttr::type target_type = rttr::type::get<int>();
bool found = false;
for (const std::string &t : {"TimelineModel"}) {
for (const std::string &t : {"TimelineModel", "TimelineFunctions"}) {
rttr::type current_type = rttr::type::get_by_name(t);
// std::cout << "type " << t << " has methods count=" << current_type.get_methods().size() << std::endl;
std::cout << "type " << t << " has methods count=" << current_type.get_methods().size() << std::endl;
if (current_type.get_method(c).is_valid()) {
found = true;
target_type = current_type;
......@@ -302,6 +313,7 @@ void fuzz(const std::string &input)
}
}
if (found) {
std::cout << "found!" << std::endl;
bool valid = true;
rttr::method target_method = target_type.get_method(c);
std::vector<rttr::variant> arguments;
......@@ -316,7 +328,7 @@ void fuzz(const std::string &input)
for (const auto &p : target_method.get_parameter_infos()) {
++i;
std::string arg_name = p.get_name().to_string();
// std::cout << arg_name << std::endl;
std::cout << arg_name << std::endl;
if (arg_name == "compoId") {
std::shared_ptr<TimelineModel> tim =
(ptr.can_convert<std::shared_ptr<TimelineModel>>() ? ptr.convert<std::shared_ptr<TimelineModel>>() : nullptr);
......@@ -330,7 +342,7 @@ void fuzz(const std::string &input)
int clipId = get_clip(tim);
valid = valid && (clipId >= 0);
arguments.emplace_back(clipId);
// std::cout << "got clipId" << clipId << std::endl;
std::cout << "got clipId" << clipId << std::endl;
} else if (arg_name == "trackId") {
std::shared_ptr<TimelineModel> tim =
(ptr.can_convert<std::shared_ptr<TimelineModel>>() ? ptr.convert<std::shared_ptr<TimelineModel>>() : nullptr);
......@@ -381,7 +393,19 @@ void fuzz(const std::string &input)
if (arg_type == rttr::type::get<int>()) {
int a = 0;
ss >> a;
// std::cout << "read int " << a << std::endl;
std::cout << "read int " << a << std::endl;
arguments.emplace_back(a);
} else if (arg_type == rttr::type::get<size_t>()) {
size_t a = 0;
ss >> a;
arguments.emplace_back(a);
} else if (arg_type == rttr::type::get<double>()) {
double a = 0;
ss >> a;
arguments.emplace_back(a);
} else if (arg_type == rttr::type::get<float>()) {
float a = 0;
ss >> a;
arguments.emplace_back(a);
} else if (arg_type == rttr::type::get<bool>()) {
bool a = false;
......@@ -396,6 +420,17 @@ void fuzz(const std::string &input)
str = "";
}
arguments.emplace_back(QString::fromStdString(str));
} else if (arg_type == rttr::type::get<std::shared_ptr<TimelineItemModel>>()) {
auto timeline = get_timeline();
if (timeline) {
std::cout << "got timeline" << std::endl;
auto timeline2 = std::dynamic_pointer_cast<TimelineItemModel>(timeline);
arguments.emplace_back(timeline2);
ptr = timeline;
} else {
std::cout << "didn't get timeline" << std::endl;
valid = false;
}
} else if (arg_type.is_enumeration()) {
int a = 0;
ss >> a;
......@@ -416,15 +451,15 @@ void fuzz(const std::string &input)
}
}
if (valid) {
// std::cout << "VALID!!!" << std::endl;
std::cout << "VALID!!! " << target_method.get_name().to_string() << std::endl;
std::vector<rttr::argument> args;
args.reserve(arguments.size());
for (const auto &a : arguments) {
for (auto &a : arguments) {
args.emplace_back(a);
// std::cout<<"argument="<<a.get_type().get_name().to_string()<<std::endl;
std::cout << "argument=" << a.get_type().get_name().to_string() << std::endl;
}
for (const auto &p : target_method.get_parameter_infos()) {
// std::cout<<"expected="<<p.get_type().get_name().to_string()<<std::endl;
std::cout << "expected=" << p.get_type().get_name().to_string() << std::endl;
}
rttr::variant res = target_method.invoke_variadic(ptr, args);
if (res.is_valid()) {
......
......@@ -41,6 +41,11 @@ RTTR_REGISTRATION
value("AVSplit", GroupType::AVSplit),
value("Leaf", GroupType::Leaf)
);
registration::enumeration<PlaylistState::ClipState>("PlaylistState")(
value("VideoOnly", PlaylistState::VideoOnly),
value("AudioOnly", PlaylistState::AudioOnly),
value("Disabled", PlaylistState::Disabled)
);
// clang-format on
}
......
......@@ -22,6 +22,7 @@
#include "logger.hpp"
#include "bin/projectitemmodel.h"
#include "timeline2/model/timelinefunctions.hpp"
#include "timeline2/model/timelineitemmodel.hpp"
#include "timeline2/model/timelinemodel.hpp"
#include <QString>
#include <fstream>
......@@ -66,7 +67,7 @@ void Logger::init()
}
};
for (const auto &o : {"TimelineModel", "TrackModel", "test_producer", "test_producer_sound"}) {
for (const auto &o : {"TimelineModel", "TrackModel", "test_producer", "test_producer_sound", "ClipModel"}) {
translation_table[std::string("constr_") + o] = cur_ind;
incr_ind(incr_ind);
}
......@@ -106,6 +107,8 @@ std::string Logger::get_ptr_name(const rttr::variant &ptr)
return "timeline_" + std::to_string(get_id_from_ptr(ptr.convert<TimelineModel *>()));
} else if (ptr.can_convert<ProjectItemModel *>()) {
return "binModel";
} else if (ptr.can_convert<TimelineItemModel *>()) {
return "timeline_" + std::to_string(get_id_from_ptr(static_cast<TimelineModel *>(ptr.convert<TimelineItemModel *>())));
} else {
std::cout << "Error: unhandled ptr type " << ptr.get_type().get_name().to_string() << std::endl;
}
......@@ -175,6 +178,12 @@ void Logger::print_trace()
ss << "dummy_" << i;
} else if (a.get_type() == rttr::type::get<int>()) {
ss << a.convert<int>();
} else if (a.get_type() == rttr::type::get<double>()) {
ss << a.convert<double>();
} else if (a.get_type() == rttr::type::get<float>()) {
ss << a.convert<float>();
} else if (a.get_type() == rttr::type::get<size_t>()) {
ss << a.convert<size_t>();
} else if (a.get_type() == rttr::type::get<bool>()) {
ss << (a.convert<bool>() ? "true" : "false");
} else if (a.get_type().is_enumeration()) {
......@@ -220,6 +229,12 @@ void Logger::print_trace()
continue;
} else if (a.get_type() == rttr::type::get<int>()) {
ss << a.convert<int>();
} else if (a.get_type() == rttr::type::get<double>()) {
ss << a.convert<double>();
} else if (a.get_type() == rttr::type::get<float>()) {
ss << a.convert<float>();
} else if (a.get_type() == rttr::type::get<size_t>()) {
ss << a.convert<size_t>();
} else if (a.get_type() == rttr::type::get<bool>()) {
ss << (a.convert<bool>() ? "1" : "0");
} else if (a.get_type().is_enumeration()) {
......@@ -250,6 +265,8 @@ void Logger::print_trace()
} else if (a.get_type().is_pointer()) {
if (a.can_convert<TimelineModel *>()) {
ss << get_id_from_ptr(a.convert<TimelineModel *>());
} else if (a.can_convert<TimelineItemModel *>()) {
ss << get_id_from_ptr(static_cast<TimelineModel *>(a.convert<TimelineItemModel *>()));
} else if (a.can_convert<ProjectItemModel *>()) {
// only one binModel, we skip the parameter since it's unambiguous
} else {
......@@ -288,7 +305,16 @@ void Logger::print_trace()
InvokId id = o.convert<Logger::InvokId>();
Invok &invok = invoks[id.id];
std::unordered_set<size_t> refs;
bool is_static = false;
rttr::method m = invok.ptr.get_type().get_method(invok.method);
if (!m.is_valid()) {
is_static = true;
m = rttr::type::get_by_name("TimelineFunctions").get_method(invok.method);
}
if (!m.is_valid()) {
std::cout << "ERROR: unknown method " << invok.method << std::endl;
continue;
}
test_file << "{" << std::endl;
for (const auto &a : m.get_parameter_infos()) {
if (isIthParamARef(m, a.get_index())) {
......@@ -300,7 +326,12 @@ void Logger::print_trace()
if (m.get_return_type() != rttr::type::get<void>()) {
test_file << m.get_return_type().get_name().to_string() << " res = ";
}
test_file << get_ptr_name(invok.ptr) << "->" << invok.method << "(" << process_args(invok.args, refs) << ");" << std::endl;
if (is_static) {
test_file << "TimelineFunctions::" << invok.method << "(" << get_ptr_name(invok.ptr) << ", " << process_args(invok.args, refs) << ");"
<< std::endl;
} else {
test_file << get_ptr_name(invok.ptr) << "->" << invok.method << "(" << process_args(invok.args, refs) << ");" << std::endl;
}
if (m.get_return_type() != rttr::type::get<void>() && invok.res.is_valid()) {
test_file << "REQUIRE( res == " << invok.res.to_string() << ");" << std::endl;
}
......@@ -309,7 +340,8 @@ void Logger::print_trace()
std::string invok_name = invok.method;
if (translation_table.count(invok_name) > 0) {
auto args = invok.args;
if (rttr::type::get<TimelineModel>().get_method(invok_name).is_valid()) {
if (rttr::type::get<TimelineModel>().get_method(invok_name).is_valid() ||
rttr::type::get<TimelineFunctions>().get_method(invok_name).is_valid()) {
args.insert(args.begin(), invok.ptr);
// adding an arg just messed up the references
std::unordered_set<size_t> new_refs;
......@@ -341,6 +373,9 @@ void Logger::print_trace()
} else if (id.type == "TrackModel") {
std::string params = process_args(constr[id.type][id.id].second);
test_file << "TrackModel::construct(" << params << ");" << std::endl;
} else if (id.type == "ClipModel") {
std::string params = process_args(constr[id.type][id.id].second);
test_file << "ClipModel::construct(" << params << ");" << std::endl;
} else if (id.type == "test_producer") {
std::string params = process_args(constr[id.type][id.id].second);
test_file << "createProducer(reg_profile, " << params << ");" << std::endl;
......
......@@ -23,6 +23,7 @@
#include "bin/projectitemmodel.h"
#include "core.h"
#include "effects/effectstack/model/effectstackmodel.hpp"
#include "logger.hpp"
#include "macros.hpp"
#include "timelinemodel.hpp"
#include "trackmodel.hpp"
......@@ -77,6 +78,7 @@ int ClipModel::construct(const std::shared_ptr<TimelineModel> &parent, const QSt
state = stateFromBool(videoAudio);
std::shared_ptr<Mlt::Producer> cutProducer = binClip->getTimelineProducer(-1, id, state, speed);
std::shared_ptr<ClipModel> clip(new ClipModel(parent, cutProducer, binClipId, id, state, speed));
TRACE_CONSTR(clip.get(), parent, binClipId, id, state, speed);
clip->setClipState_lambda(state)();
parent->registerClip(clip);
return id;
......
......@@ -39,6 +39,20 @@
#include <mlt++/MltTractor.h>
#include <mlt++/MltTransition.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wsign-conversion"
#pragma GCC diagnostic ignored "-Wfloat-equal"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wpedantic"
#include <rttr/registration>
#pragma GCC diagnostic pop
RTTR_REGISTRATION
{
using namespace rttr;
registration::class_<TimelineItemModel>("TimelineItemModel");
}
TimelineItemModel::TimelineItemModel(Mlt::Profile *profile, std::weak_ptr<DocUndoStack> undo_stack)
: TimelineModel(profile, std::move(undo_stack))
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment