summaryrefslogtreecommitdiffstats
path: root/src/piklab-test
diff options
context:
space:
mode:
Diffstat (limited to 'src/piklab-test')
-rw-r--r--src/piklab-test/Makefile.am3
-rw-r--r--src/piklab-test/base/Makefile.am5
-rw-r--r--src/piklab-test/base/device_test.cpp54
-rw-r--r--src/piklab-test/base/device_test.h32
-rw-r--r--src/piklab-test/base/generator_check.cpp288
-rw-r--r--src/piklab-test/base/generator_check.h102
-rw-r--r--src/piklab-test/base/main_test.cpp32
-rw-r--r--src/piklab-test/base/main_test.h51
-rw-r--r--src/piklab-test/checksum/Makefile.am18
-rw-r--r--src/piklab-test/checksum/checksum_check.cpp116
-rw-r--r--src/piklab-test/checksum/checksum_check.h35
-rw-r--r--src/piklab-test/generators/Makefile.am31
-rw-r--r--src/piklab-test/generators/gputils_config_generator_check.cpp11
-rw-r--r--src/piklab-test/generators/gputils_config_generator_check.h20
-rw-r--r--src/piklab-test/generators/gputils_template_generator_check.cpp11
-rw-r--r--src/piklab-test/generators/gputils_template_generator_check.h20
-rw-r--r--src/piklab-test/generators/sdcc_config_generator_check.cpp11
-rw-r--r--src/piklab-test/generators/sdcc_config_generator_check.h20
-rw-r--r--src/piklab-test/misc/Makefile.am10
-rw-r--r--src/piklab-test/misc/misc_check.cpp99
-rw-r--r--src/piklab-test/misc/misc_check.h20
-rw-r--r--src/piklab-test/save_load_memory/Makefile.am18
-rw-r--r--src/piklab-test/save_load_memory/save_load_memory_check.cpp64
-rw-r--r--src/piklab-test/save_load_memory/save_load_memory_check.h32
24 files changed, 1103 insertions, 0 deletions
diff --git a/src/piklab-test/Makefile.am b/src/piklab-test/Makefile.am
new file mode 100644
index 0000000..7159e70
--- /dev/null
+++ b/src/piklab-test/Makefile.am
@@ -0,0 +1,3 @@
+INCLUDES = -I$(top_srcdir)/src $(all_includes)
+METASOURCES = AUTO
+SUBDIRS = base misc save_load_memory checksum generators
diff --git a/src/piklab-test/base/Makefile.am b/src/piklab-test/base/Makefile.am
new file mode 100644
index 0000000..da6c4ba
--- /dev/null
+++ b/src/piklab-test/base/Makefile.am
@@ -0,0 +1,5 @@
+INCLUDES = -I$(top_srcdir)/src $(all_includes)
+METASOURCES = AUTO
+
+noinst_LTLIBRARIES = libtest.la
+libtest_la_SOURCES = main_test.cpp device_test.cpp generator_check.cpp
diff --git a/src/piklab-test/base/device_test.cpp b/src/piklab-test/base/device_test.cpp
new file mode 100644
index 0000000..9346a13
--- /dev/null
+++ b/src/piklab-test/base/device_test.cpp
@@ -0,0 +1,54 @@
+/***************************************************************************
+ * Copyright (C) 2007 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#include "device_test.h"
+
+#include "devices/base/device_group.h"
+#include "devices/list/device_list.h"
+
+void DeviceTest::checkArguments()
+{
+ if ( _args->count()==1 ) {
+ _device = QString(_args->arg(0)).upper();
+ if ( !Device::lister().isSupported(_device) ) qFatal("Specified device \"%s\" not supported.", _device.latin1());
+ printf("Testing only %s\n", _device.latin1());
+ }
+}
+
+bool DeviceTest::execute()
+{
+ Device::Lister::ConstIterator it;
+ for (it=Device::lister().begin(); it!=Device::lister().end(); ++it) {
+ Group::Base::ConstIterator git;
+ for (git=it.data()->begin(); git!=it.data()->end(); ++git) {
+ const Device::Data &data = *git.data().data;
+ if ( !_device.isEmpty() && data.name()!=_device ) continue;
+ _message = data.name();
+ if ( skip(data) ) {
+ skipped();
+ printf("S");
+ } else {
+ if ( init(data) ) {
+ printf("*");
+ execute(data);
+ } else printf("S");
+ cleanup(data);
+ }
+ fflush(stdout);
+ }
+ }
+ return true;
+}
+
+Piklab::OptionList DeviceTest::optionList() const
+{
+ Piklab::OptionList optionList;
+ const KCmdLineOptions OPTION = { "+[device]", "Only check the specified device", 0 };
+ optionList.append(OPTION);
+ return optionList;
+}
diff --git a/src/piklab-test/base/device_test.h b/src/piklab-test/base/device_test.h
new file mode 100644
index 0000000..24447ed
--- /dev/null
+++ b/src/piklab-test/base/device_test.h
@@ -0,0 +1,32 @@
+/***************************************************************************
+ * Copyright (C) 2007 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#ifndef DEVICE_TEST_H
+#define DEVICE_TEST_H
+
+#include "piklab-test/base/main_test.h"
+namespace Device { class Data; }
+
+class DeviceTest : public Test
+{
+public:
+ virtual Piklab::OptionList optionList() const;
+
+protected:
+ virtual bool execute();
+ virtual bool skip(const Device::Data &) const { return false; }
+ virtual bool init(const Device::Data &) { return true; } // returns false if skipped or failed
+ virtual bool execute(const Device::Data &data) = 0; // returns false if skipped or failed
+ virtual void cleanup(const Device::Data &) {}
+ virtual void checkArguments();
+
+private:
+ QString _device;
+};
+
+#endif
diff --git a/src/piklab-test/base/generator_check.cpp b/src/piklab-test/base/generator_check.cpp
new file mode 100644
index 0000000..68ad2c5
--- /dev/null
+++ b/src/piklab-test/base/generator_check.cpp
@@ -0,0 +1,288 @@
+/***************************************************************************
+ * Copyright (C) 2007 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#include "generator_check.h"
+
+#include "devices/base/device_group.h"
+#include "devices/pic/pic/pic_memory.h"
+#include "tools/gputils/gputils.h"
+#include "tools/gputils/gputils_generator.h"
+#include "tools/sdcc/sdcc.h"
+#include "tools/sdcc/sdcc_generator.h"
+#include "devices/list/device_list.h"
+
+//----------------------------------------------------------------------------
+GeneratorCheckHelper::GeneratorCheckHelper()
+ : _cprocess(0), _lprocess(0), _generator(0)
+{}
+
+GeneratorCheckHelper::~GeneratorCheckHelper()
+{
+ delete _generator;
+}
+
+void GeneratorCheckHelper::cleanup()
+{
+ delete _lprocess;
+ _lprocess = 0;
+ delete _cprocess;
+ _cprocess = 0;
+}
+
+//----------------------------------------------------------------------------
+GeneratorCheck::GeneratorCheck(GeneratorCheckHelper *helper)
+ : _helper(helper), _fdest(0), _fhex(0), _memory1(0)
+{
+ _view = new CLI::View;
+}
+
+GeneratorCheck::~GeneratorCheck()
+{
+ delete _view;
+ delete _helper;
+}
+
+void GeneratorCheck::runTest()
+{
+ _helper->initSupported();
+ DeviceTest::runTest();
+}
+
+bool GeneratorCheck::init(const Device::Data &data)
+{
+ PURL::Url dest(PURL::Directory::current(), "test.xxx");
+ dest = dest.toFileType(_helper->sourceFileType());
+ _fdest = new PURL::File(dest, *_view);
+ _helper->init(data);
+ PURL::Url hex(PURL::Directory::current(), "test.hex");
+ _fhex = new PURL::File(hex, *_view);
+ _memory1 = static_cast<Pic::Memory *>(data.group().createMemory(data));
+ return true;
+}
+
+bool GeneratorCheck::skip(const Device::Data &data) const
+{
+ return !_helper->isSupported(data);
+}
+
+void GeneratorCheck::cleanup(const Device::Data &)
+{
+ delete _memory1;
+ _memory1 = 0;
+ delete _fhex;
+ _fhex = 0;
+// _fdest->remove();
+ delete _fdest;
+ _fdest = 0;
+ _helper->cleanup();
+}
+
+bool GeneratorCheck::execute(const Device::Data &data)
+{
+ // create asm file from template source code
+ if ( !_fdest->openForWrite() ) TEST_FAILED_RETURN("");
+ _fdest->appendText(_source);
+ _fdest->close();
+
+ // run compiler
+ Process::State state = Process::runSynchronously(*_helper->_cprocess, Process::Start, 2000); // 2s timeout
+ if ( state!=Process::Exited ) TEST_FAILED_RETURN("Error while running compilation")
+ if ( _helper->_cprocess->exitCode()!=0 ) TEST_FAILED_RETURN(QString("Error in compilation for %1:\n%2%3").arg(data.name()).arg(_helper->_cprocess->sout()+_helper->_cprocess->serr()).arg(QString::null))
+
+ // run linker
+ if (_helper->_lprocess) {
+ state = Process::runSynchronously(*_helper->_lprocess, Process::Start, 2000); // 2s timeout
+ if ( state!=Process::Exited ) TEST_FAILED_RETURN("Error while running linking")
+ if ( _helper->_lprocess->exitCode()!=0 ) TEST_FAILED_RETURN(QString("Error in linking for %1:\n%2%3").arg(data.name()).arg(_helper->_lprocess->sout()+_helper->_lprocess->serr()).arg(QString::null))
+ }
+
+ // load hex file
+ if ( !_fhex->openForRead() ) TEST_FAILED_RETURN("")
+ QStringList errors, warnings;
+ Device::Memory::WarningTypes warningTypes;
+ if ( !_memory1->load(_fhex->stream(), errors, warningTypes, warnings) ) TEST_FAILED_RETURN(QString("Error loading hex into memory: %1").arg(errors.join(" ")))
+ //if ( warningTypes!=Device::Memory::NoWarning ) TEST_FAILED(QString("Warning loading hex into memory: %1").arg(warnings.join(" ")))
+
+ TEST_PASSED
+ return true;
+}
+
+//----------------------------------------------------------------------------
+bool ConfigGeneratorCheck::init(const Device::Data &data)
+{
+ if ( !GeneratorCheck::init(data) ) return false;
+ _memory2 = static_cast<Pic::Memory *>(data.group().createMemory(data));
+ return true;
+}
+
+bool ConfigGeneratorCheck::execute(const Device::Data &data)
+{
+ // create configuration
+ const Pic::Config &config = static_cast<const Pic::Data &>(data).config();
+ for (uint l=0; ; l++) {
+ // set config bits
+ bool ok = false;
+ for (uint i=0; i<config._words.count(); i++) {
+ const Pic::Config::Word &cword = config._words[i];
+ for (uint k=0; k<cword.masks.count(); k++) {
+ const Pic::Config::Mask &cmask = cword.masks[k];
+ if ( l<cmask.values.count() ) {
+ ok = true;
+ if ( !cmask.values[l].name.isEmpty() ) _memory2->setConfigValue(cmask.name, cmask.values[l].name);
+ }
+ }
+ }
+ if ( !ok ) break;
+
+ // create source code
+ PURL::SourceFamily sfamily = _helper->sourceFileType().data().sourceFamily;
+ PURL::ToolType ttype = sfamily.data().toolType;
+ SourceLine::List lines = _helper->generator()->includeLines(ttype, data);
+ lines += _helper->generator()->configLines(ttype, *_memory2, ok);
+ lines += _helper->configEndLines();
+ _source = SourceLine::text(sfamily, lines, 2);
+ if (!ok) TEST_FAILED_RETURN("Config lines generation incomplete")
+
+ if ( !GeneratorCheck::execute(data) ) return false;
+
+ // check that config bits are the same
+ uint nbChars = static_cast<const Pic::Data &>(data).nbCharsWord(Pic::MemoryRangeType::Config);
+ for (uint i=0; i<config._words.count(); i++) {
+ const Pic::Config::Word &cword = config._words[i];
+ BitValue word1 = _memory1->word(Pic::MemoryRangeType::Config, i);
+ BitValue word2 = _memory2->word(Pic::MemoryRangeType::Config, i);
+ if ( word1==word2 ) continue;
+ for (uint k=0; k<cword.masks.count(); k++) {
+ const Pic::Config::Mask &cmask = cword.masks[k];
+ if ( cmask.value.isInside(cword.pmask) ) continue;
+ BitValue value1 = word1.maskWith(cmask.value);
+ BitValue value2 = word2.maskWith(cmask.value);
+ if ( value1==value2 ) continue;
+ QString name1, name2;
+ uint l1, l2;
+ for (uint l=0; l<cmask.values.count(); l++) {
+ const Pic::Config::Value &value = cmask.values[l];
+ if ( value.value==value1 ) { name1 = value.name; l1 = l; }
+ if ( value.value==value2 ) { name2 = value.name; l2 = l; }
+ }
+ if ( name1==name2 ) continue;
+ TEST_FAILED_RETURN(QString("Config bits are different in %1: set\"%2\"=(%3) != compiled=%4)")
+ .arg(cmask.name).arg(cmask.values[l2].name)
+ .arg(toHexLabel(word2.maskWith(cmask.value), nbChars)).arg(toHexLabel(word1.maskWith(cmask.value), nbChars)))
+ }
+ }
+ }
+
+ TEST_PASSED
+ return true;
+}
+
+void ConfigGeneratorCheck::cleanup(const Device::Data &data)
+{
+ GeneratorCheck::cleanup(data);
+ delete _memory2;
+ _memory2 = 0;
+}
+
+//----------------------------------------------------------------------------
+bool TemplateGeneratorCheck::init(const Device::Data &data)
+{
+ if ( !GeneratorCheck::init(data) ) return false;
+ bool ok;
+ PURL::SourceFamily sfamily = _helper->sourceFileType().data().sourceFamily;
+ PURL::ToolType ttype = sfamily.data().toolType;
+ SourceLine::List lines = _helper->generator()->templateSourceFile(ttype, data, ok);
+ _source = SourceLine::text(sfamily, lines, 2);
+ if (!ok) TEST_FAILED_RETURN(QString("Incomplete template generator for %1").arg(data.name()))
+ return true;
+}
+
+//----------------------------------------------------------------------------
+GPUtilsGeneratorCheckHelper::GPUtilsGeneratorCheckHelper()
+{
+ _generator = new GPUtils::SourceGenerator;
+}
+
+void GPUtilsGeneratorCheckHelper::initSupported()
+{
+ Process::StringOutput p;
+ QStringList options;
+ options += "-l";
+ p.setup("gpasm", options, false);
+ Process::runSynchronously(p, Process::Start, 2000); // 2s timeout
+ _supported = GPUtils::getSupportedDevices(p.sout());
+}
+
+bool GPUtilsGeneratorCheckHelper::init(const Device::Data &data)
+{
+ _cprocess = new Process::StringOutput;
+ QStringList options;
+ options = "-c";
+ options += "-p" + GPUtils::toDeviceName(data.name());
+ options += "test.asm";
+ _cprocess->setup("gpasm", options, false);
+ _lprocess = new Process::StringOutput;
+ options = "-o";
+ options += "test.hex";
+ options += "test.o";
+ _lprocess->setup("gplink", options, false);
+ return true;
+}
+
+SourceLine::List GPUtilsGeneratorCheckHelper::configEndLines() const
+{
+ SourceLine::List lines;
+ lines.appendIndentedCode("end");
+ return lines;
+}
+
+//----------------------------------------------------------------------------
+SDCCGeneratorCheckHelper::SDCCGeneratorCheckHelper()
+{
+ _generator = new SDCC::SourceGenerator;
+}
+
+void SDCCGeneratorCheckHelper::initSupported()
+{
+ PURL::Url url(PURL::Directory::current(), "test.c");
+ Log::StringView view;
+ PURL::File file(url, view);
+ if ( file.openForWrite() ) file.appendText("void main(void) {}\n");
+ file.close();
+ _supported.clear();
+ for (uint i=0; i<SDCC::Nb_Families; i++) {
+ Process::StringOutput p;
+ QStringList options;
+ options += QString("-m") + SDCC::FAMILY_DATA[i].name;
+ options += "-phelp";
+ options += "test.c";
+ p.setup("sdcc", options, false);
+ Process::runSynchronously(p, Process::Start, 2000); // 2s timeout
+ _supported += SDCC::getSupportedDevices(p.serr());
+ }
+}
+
+bool SDCCGeneratorCheckHelper::init(const Device::Data &data)
+{
+ _cprocess = new Process::StringOutput;
+ QStringList options;
+ options += QString("-m") + SDCC::FAMILY_DATA[SDCC::family(data.name())].name;
+ options += "-" + SDCC::toDeviceName(data.name());
+ options += "test.c";
+ options += "-I/usr/share/gputils/header";
+ options += "-Wl-otext.hex";
+ _cprocess->setup("sdcc", options, false);
+ return true;
+}
+
+SourceLine::List SDCCGeneratorCheckHelper::configEndLines() const
+{
+ SourceLine::List lines;
+ lines.appendIndentedCode("void main() {}");
+ return lines;
+}
diff --git a/src/piklab-test/base/generator_check.h b/src/piklab-test/base/generator_check.h
new file mode 100644
index 0000000..9ad426a
--- /dev/null
+++ b/src/piklab-test/base/generator_check.h
@@ -0,0 +1,102 @@
+/***************************************************************************
+ * Copyright (C) 2007 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#ifndef GPUTILS_GENERATOR_CHECK_H
+#define GPUTILS_GENERATOR_CHECK_H
+
+#include "device_test.h"
+#include "common/cli/cli_log.h"
+#include "common/global/pfile.h"
+#include "coff/base/disassembler.h"
+#include "common/global/process.h"
+namespace Pic { class Memory; }
+
+//----------------------------------------------------------------------------
+class GeneratorCheckHelper
+{
+public:
+ GeneratorCheckHelper();
+ virtual ~GeneratorCheckHelper();
+ virtual void initSupported() = 0;
+ virtual bool init(const Device::Data &data) = 0;
+ void cleanup();
+ bool isSupported(const Device::Data &data) const { return _supported.contains(&data); }
+ virtual PURL::FileType sourceFileType() const = 0;
+ const Tool::SourceGenerator *generator() const { return _generator; }
+ virtual SourceLine::List configEndLines() const = 0;
+
+protected:
+ QValueList<const Device::Data *> _supported;
+ Process::StringOutput *_cprocess, *_lprocess;
+ Tool::SourceGenerator *_generator;
+
+ friend class GeneratorCheck;
+};
+
+class GeneratorCheck : public DeviceTest
+{
+public:
+ GeneratorCheck(GeneratorCheckHelper *helper);
+ virtual ~GeneratorCheck();
+ virtual bool skip(const Device::Data &data) const;
+ virtual void runTest();
+ virtual bool init(const Device::Data &data);
+ virtual bool execute(const Device::Data &data);
+ virtual void cleanup(const Device::Data &data);
+
+protected:
+ GeneratorCheckHelper *_helper;
+ CLI::View *_view;
+ PURL::File *_fdest, *_fhex;
+ Pic::Memory *_memory1;
+ QString _source;
+};
+
+//----------------------------------------------------------------------------
+class ConfigGeneratorCheck : public GeneratorCheck
+{
+public:
+ ConfigGeneratorCheck(GeneratorCheckHelper *helper) : GeneratorCheck(helper), _memory2(0) {}
+ virtual bool init(const Device::Data &data);
+ virtual bool execute(const Device::Data &data);
+ virtual void cleanup(const Device::Data &data);
+
+private:
+ Pic::Memory *_memory2;
+};
+
+//----------------------------------------------------------------------------
+class TemplateGeneratorCheck : public GeneratorCheck
+{
+public:
+ TemplateGeneratorCheck(GeneratorCheckHelper *helper) : GeneratorCheck(helper) {}
+ virtual bool init(const Device::Data &data);
+};
+
+//----------------------------------------------------------------------------
+class GPUtilsGeneratorCheckHelper : public GeneratorCheckHelper
+{
+public:
+ GPUtilsGeneratorCheckHelper();
+ virtual void initSupported();
+ virtual bool init(const Device::Data &data);
+ virtual PURL::FileType sourceFileType() const { return PURL::AsmGPAsm; }
+ virtual SourceLine::List configEndLines() const;
+};
+
+//----------------------------------------------------------------------------
+class SDCCGeneratorCheckHelper : public GeneratorCheckHelper
+{
+public:
+ SDCCGeneratorCheckHelper();
+ virtual void initSupported();
+ virtual bool init(const Device::Data &data);
+ virtual PURL::FileType sourceFileType() const { return PURL::CSource; }
+ virtual SourceLine::List configEndLines() const;
+};
+#endif
diff --git a/src/piklab-test/base/main_test.cpp b/src/piklab-test/base/main_test.cpp
new file mode 100644
index 0000000..10d0414
--- /dev/null
+++ b/src/piklab-test/base/main_test.cpp
@@ -0,0 +1,32 @@
+/***************************************************************************
+ * Copyright (C) 2007 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#include "main_test.h"
+
+//----------------------------------------------------------------------------
+Test::Test()
+ : _nbPassed(0), _nbFailed(0), _nbSkipped(0)
+{}
+
+void Test::runTest()
+{
+ _args = KCmdLineArgs::parsedArgs();
+ checkArguments();
+ fflush(stdout);
+ execute();
+ printf("\n");
+ printf("RESULTS: %i PASSED / %i FAILED / %i SKIPPED \n", _nbPassed, _nbFailed, _nbSkipped);
+}
+
+void Test::failed(const QString &message, const char *file, int line)
+{
+ _nbFailed++;
+ printf("\n");
+ if ( !_message.isEmpty() ) printf("[%s]", _message.latin1());
+ printf("FAILED in \"%s\" line #%i: %s\n", file, line, message.latin1());
+}
diff --git a/src/piklab-test/base/main_test.h b/src/piklab-test/base/main_test.h
new file mode 100644
index 0000000..601b779
--- /dev/null
+++ b/src/piklab-test/base/main_test.h
@@ -0,0 +1,51 @@
+/***************************************************************************
+ * Copyright (C) 2007 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#ifndef MAIN_TEST_H
+#define MAIN_TEST_H
+
+#include "common/global/about.h"
+
+//----------------------------------------------------------------------------
+#define TEST_SKIPPED_RETURN { skipped(); return false; }
+#define TEST_FAILED_RETURN(message) { failed(message, __FILE__, __LINE__); return false; }
+#define TEST_FAILED(message) { failed(message, __FILE__, __LINE__); }
+#define TEST_PASSED { printf("."); fflush(stdout); passed(); }
+#define TEST_MAIN(Type) \
+ int main(int argc, char **argv) \
+ { \
+ Type *check = new Type; \
+ Piklab::OptionList opt = check->optionList(); \
+ Piklab::init(new Piklab::AboutData("test", 0, 0), argc, argv, false, opt.ptr()); \
+ check->runTest(); \
+ return 0; \
+ }
+
+//----------------------------------------------------------------------------
+class Test
+{
+public:
+ Test();
+ virtual Piklab::OptionList optionList() const { return Piklab::OptionList(); }
+ virtual void runTest();
+
+protected:
+ KCmdLineArgs *_args;
+ QString _message;
+
+ void passed() { _nbPassed++; }
+ void failed(const QString &message, const char *file, int line);
+ void skipped() { _nbSkipped++; }
+ virtual bool execute() = 0; // returns false if failed or skipped
+ virtual void checkArguments() {}
+
+private:
+ uint _nbPassed, _nbFailed, _nbSkipped;
+};
+
+#endif
diff --git a/src/piklab-test/checksum/Makefile.am b/src/piklab-test/checksum/Makefile.am
new file mode 100644
index 0000000..ed7535d
--- /dev/null
+++ b/src/piklab-test/checksum/Makefile.am
@@ -0,0 +1,18 @@
+INCLUDES = -I$(top_srcdir)/src $(all_includes)
+METASOURCES = AUTO
+
+noinst_PROGRAMS = checksum_check
+OBJ = $(top_builddir)/src/piklab-test/base/libtest.la \
+ $(top_builddir)/src/common/cli/libcli.la \
+ $(top_builddir)/src/tools/gputils/libgputils.la \
+ $(top_builddir)/src/coff/base/libcoff.la \
+ $(top_builddir)/src/common/global/libglobal.la $(top_builddir)/src/devices/list/libdevicelistnoui.la \
+ $(top_builddir)/src/devices/pic/pic/libpic.la $(top_builddir)/src/devices/pic/base/libpicbase.la \
+ $(top_builddir)/src/devices/pic/xml_data/libpicxml.la \
+ $(top_builddir)/src/devices/mem24/mem24/libmem24.la $(top_builddir)/src/devices/mem24/base/libmem24base.la \
+ $(top_builddir)/src/devices/mem24/xml_data/libmem24xml.la \
+ $(top_builddir)/src/devices/base/libdevicebase.la $(top_builddir)/src/common/common/libcommon.la
+checksum_check_DEPENDENCIES = $(OBJ)
+checksum_check_LDADD = $(OBJ) $(LIB_KIO)
+checksum_check_LDFLAGS = $(all_libraries) $(KDE_RPATH)
+checksum_check_SOURCES = checksum_check.cpp
diff --git a/src/piklab-test/checksum/checksum_check.cpp b/src/piklab-test/checksum/checksum_check.cpp
new file mode 100644
index 0000000..fdba104
--- /dev/null
+++ b/src/piklab-test/checksum/checksum_check.cpp
@@ -0,0 +1,116 @@
+/***************************************************************************
+ * Copyright (C) 2007 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#include "checksum_check.h"
+
+#include "devices/base/device_group.h"
+
+//----------------------------------------------------------------------------
+bool ChecksumCheck::skip(const Device::Data &data) const
+{
+ return ( data.group().name()!="pic" );
+}
+
+bool ChecksumCheck::init(const Device::Data &data)
+{
+ _memory = static_cast<Pic::Memory *>(data.group().createMemory(data));
+ return true;
+}
+
+void ChecksumCheck::cleanup(const Device::Data &)
+{
+ delete _memory;
+ _memory = 0;
+}
+
+void ChecksumCheck::setProtection(const Pic::Data &data, const Pic::Checksum::Data &cdata,
+ const QString &maskName, const QString &valueName)
+{
+ const Pic::Protection &protection = data.config().protection();
+ if ( !maskName.isEmpty() && !valueName.isEmpty() ) _memory->setConfigValue(maskName, valueName);
+ if ( !valueName.isEmpty() ) _memory->setUserIdToUnprotectedChecksum();
+ for (uint i=0; i<cdata.protectedMaskNames.count(); i++) {
+ QString pmName = cdata.protectedMaskNames[i];
+ const Pic::Config::Mask *mask = data.config().findMask(pmName, 0);
+ for (int k=mask->values.count()-1; k>=0; k--) {
+ if ( mask->values[k].name.isEmpty() ) continue;
+ if ( protection.isNoneProtectedValueName(mask->values[k].name) ) continue;
+ _memory->setConfigValue(pmName, mask->values[k].name);
+ break;
+ }
+ }
+ if ( !cdata.bbsize.isEmpty() ) _memory->setConfigValue(protection.bootSizeMaskName(), cdata.bbsize);
+}
+
+bool ChecksumCheck::checkChecksum(BitValue checksum, const QString &label)
+{
+ BitValue c = _memory->checksum();
+ if ( c!=checksum ) TEST_FAILED_RETURN(QString("%1 %2/%3").arg(label).arg(toHexLabel(c, 4)).arg(toHexLabel(checksum, 4)))
+ return true;
+}
+
+void ChecksumCheck::checkChecksum(const Pic::Data &pdata, const QString &maskName, const QString &valueName, bool &ok)
+{
+ if ( !pdata.checksums().contains(valueName) ) {
+ const Pic::Config::Mask *mask = pdata.config().findMask(maskName);
+ QString label = valueName + (mask ? "/" + mask->name : QString::null);
+ printf("Missing checksum for \"%s\"", label.latin1());
+ return;
+ }
+ const Pic::Checksum::Data &cdata = pdata.checksums()[valueName];
+ _memory->clear();
+ setProtection(pdata, cdata, maskName, valueName);
+ if ( !checkChecksum(cdata.blankChecksum, maskName + ":" + valueName + "/" + "blank") ) ok = false;
+ _memory->checksumCheckFill();
+ setProtection(pdata, cdata, maskName, valueName);
+ if ( !checkChecksum(cdata.checkChecksum, maskName + ":" + valueName + "/" + "check") ) ok = false;
+}
+
+bool ChecksumCheck::execute(const Device::Data &data)
+{
+ const Pic::Data &pdata = static_cast<const Pic::Data &>(data);
+ if ( data.name()=="18C601" || data.name()=="18C801" ) TEST_PASSED;
+ if ( pdata.checksums().isEmpty() ) TEST_FAILED_RETURN("No checksum data");
+ bool ok = true;
+ const Pic::Protection &protection = pdata.config().protection();
+ switch ( protection.family() ) {
+ case Pic::Protection::NoProtection:
+ checkChecksum(pdata, QString::null, QString::null, ok);
+ break;
+ case Pic::Protection::BasicProtection: {
+ QString maskName = protection.maskName(Pic::Protection::ProgramProtected, Pic::MemoryRangeType::Code);
+ const Pic::Config::Mask *mask = pdata.config().findMask(maskName);
+ Q_ASSERT(mask);
+ for (uint i=0; i<mask->values.count(); i++) {
+ QString valueName = mask->values[i].name;
+ if ( valueName.isEmpty() ) continue; // invalid value
+ checkChecksum(pdata, maskName, valueName, ok);
+ }
+ break;
+ }
+ case Pic::Protection::CodeGuard:
+ checkChecksum(pdata, "GSSEC", "Off", ok);
+ checkChecksum(pdata, "GSSEC", "High Security", ok);
+ break;
+ case Pic::Protection::BlockProtection: {
+ const QMap<QString, Pic::Checksum::Data> &cmap = pdata.checksums();
+ QMap<QString, Pic::Checksum::Data>::const_iterator it;
+ for (it=cmap.begin(); it!=cmap.end(); ++it)
+ checkChecksum(pdata, QString::null, it.key(), ok);
+ break;
+ }
+ case Pic::Protection::Nb_Families: Q_ASSERT(false); break;
+ }
+
+ if ( !ok ) return false;
+ TEST_PASSED
+ return true;
+}
+
+//----------------------------------------------------------------------------
+TEST_MAIN(ChecksumCheck)
diff --git a/src/piklab-test/checksum/checksum_check.h b/src/piklab-test/checksum/checksum_check.h
new file mode 100644
index 0000000..6483984
--- /dev/null
+++ b/src/piklab-test/checksum/checksum_check.h
@@ -0,0 +1,35 @@
+/***************************************************************************
+ * Copyright (C) 2007 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#ifndef CHECKSUM_CHECK_H
+#define CHECKSUM_CHECK_H
+
+#include "piklab-test/base/device_test.h"
+#include "common/cli/cli_log.h"
+#include "common/global/pfile.h"
+#include "devices/pic/pic/pic_memory.h"
+
+class ChecksumCheck : public DeviceTest
+{
+public:
+ ChecksumCheck() : _memory(0) {}
+ virtual bool skip(const Device::Data &data) const;
+ virtual bool init(const Device::Data &data);
+ virtual bool execute(const Device::Data &data);
+ virtual void cleanup(const Device::Data &data);
+
+private:
+ Pic::Memory *_memory;
+
+ void setProtection(const Pic::Data &data, const Pic::Checksum::Data &cdata,
+ const QString &maskName, const QString &valueName);
+ bool checkChecksum(BitValue checksum, const QString &label);
+ void checkChecksum(const Pic::Data &data, const QString &maskName, const QString &valueName, bool &ok);
+};
+
+#endif
diff --git a/src/piklab-test/generators/Makefile.am b/src/piklab-test/generators/Makefile.am
new file mode 100644
index 0000000..209e3e3
--- /dev/null
+++ b/src/piklab-test/generators/Makefile.am
@@ -0,0 +1,31 @@
+INCLUDES = -I$(top_srcdir)/src $(all_includes)
+METASOURCES = AUTO
+
+noinst_PROGRAMS = gputils_config_generator_check gputils_template_generator_check \
+ sdcc_config_generator_check
+
+OBJ = $(top_builddir)/src/piklab-test/base/libtest.la \
+ $(top_builddir)/src/common/cli/libcli.la \
+ $(top_builddir)/src/tools/sdcc/libsdcc.la $(top_builddir)/src/tools/gputils/libgputils.la \
+ $(top_builddir)/src/coff/base/libcoff.la \
+ $(top_builddir)/src/common/global/libglobal.la $(top_builddir)/src/devices/list/libdevicelistnoui.la \
+ $(top_builddir)/src/devices/pic/pic/libpic.la $(top_builddir)/src/devices/pic/base/libpicbase.la \
+ $(top_builddir)/src/devices/pic/xml_data/libpicxml.la \
+ $(top_builddir)/src/devices/mem24/mem24/libmem24.la $(top_builddir)/src/devices/mem24/base/libmem24base.la \
+ $(top_builddir)/src/devices/mem24/xml_data/libmem24xml.la \
+ $(top_builddir)/src/devices/base/libdevicebase.la $(top_builddir)/src/common/common/libcommon.la
+
+gputils_config_generator_check_DEPENDENCIES = $(OBJ)
+gputils_config_generator_check_LDADD = $(OBJ) $(LIB_KIO)
+gputils_config_generator_check_LDFLAGS = $(all_libraries) $(KDE_RPATH)
+gputils_config_generator_check_SOURCES = gputils_config_generator_check.cpp
+
+gputils_template_generator_check_DEPENDENCIES = $(OBJ)
+gputils_template_generator_check_LDADD = $(OBJ) $(LIB_KIO)
+gputils_template_generator_check_LDFLAGS = $(all_libraries) $(KDE_RPATH)
+gputils_template_generator_check_SOURCES = gputils_template_generator_check.cpp
+
+sdcc_config_generator_check_DEPENDENCIES = $(OBJ)
+sdcc_config_generator_check_LDADD = $(OBJ) $(LIB_KIO)
+sdcc_config_generator_check_LDFLAGS = $(all_libraries) $(KDE_RPATH)
+sdcc_config_generator_check_SOURCES = sdcc_config_generator_check.cpp
diff --git a/src/piklab-test/generators/gputils_config_generator_check.cpp b/src/piklab-test/generators/gputils_config_generator_check.cpp
new file mode 100644
index 0000000..89b2e2e
--- /dev/null
+++ b/src/piklab-test/generators/gputils_config_generator_check.cpp
@@ -0,0 +1,11 @@
+/***************************************************************************
+ * Copyright (C) 2007 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#include "gputils_config_generator_check.h"
+
+TEST_MAIN(GPUtilsConfigGeneratorCheck)
diff --git a/src/piklab-test/generators/gputils_config_generator_check.h b/src/piklab-test/generators/gputils_config_generator_check.h
new file mode 100644
index 0000000..e330871
--- /dev/null
+++ b/src/piklab-test/generators/gputils_config_generator_check.h
@@ -0,0 +1,20 @@
+/***************************************************************************
+ * Copyright (C) 2007 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#ifndef GPUTILS_CONFIG_GENERATOR_CHECK_H
+#define GPUTILS_CONFIG_GENERATOR_CHECK_H
+
+#include "piklab-test/base/generator_check.h"
+
+class GPUtilsConfigGeneratorCheck : public ConfigGeneratorCheck
+{
+public:
+ GPUtilsConfigGeneratorCheck() : ConfigGeneratorCheck(new GPUtilsGeneratorCheckHelper) {}
+};
+
+#endif
diff --git a/src/piklab-test/generators/gputils_template_generator_check.cpp b/src/piklab-test/generators/gputils_template_generator_check.cpp
new file mode 100644
index 0000000..fe5de54
--- /dev/null
+++ b/src/piklab-test/generators/gputils_template_generator_check.cpp
@@ -0,0 +1,11 @@
+/***************************************************************************
+ * Copyright (C) 2007 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#include "gputils_template_generator_check.h"
+
+TEST_MAIN(GPUtilsTemplateGeneratorCheck)
diff --git a/src/piklab-test/generators/gputils_template_generator_check.h b/src/piklab-test/generators/gputils_template_generator_check.h
new file mode 100644
index 0000000..cc93eb8
--- /dev/null
+++ b/src/piklab-test/generators/gputils_template_generator_check.h
@@ -0,0 +1,20 @@
+/***************************************************************************
+ * Copyright (C) 2007 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#ifndef GPUTILS_TEMPLATE_GENERATOR_CHECK_H
+#define GPUTILS_TEMPLATE_GENERATOR_CHECK_H
+
+#include "piklab-test/base/generator_check.h"
+
+class GPUtilsTemplateGeneratorCheck : public TemplateGeneratorCheck
+{
+public:
+ GPUtilsTemplateGeneratorCheck() : TemplateGeneratorCheck(new GPUtilsGeneratorCheckHelper) {}
+};
+
+#endif
diff --git a/src/piklab-test/generators/sdcc_config_generator_check.cpp b/src/piklab-test/generators/sdcc_config_generator_check.cpp
new file mode 100644
index 0000000..cad2f07
--- /dev/null
+++ b/src/piklab-test/generators/sdcc_config_generator_check.cpp
@@ -0,0 +1,11 @@
+/***************************************************************************
+ * Copyright (C) 2007 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#include "sdcc_config_generator_check.h"
+
+TEST_MAIN(SDCCConfigGeneratorCheck)
diff --git a/src/piklab-test/generators/sdcc_config_generator_check.h b/src/piklab-test/generators/sdcc_config_generator_check.h
new file mode 100644
index 0000000..8438f0f
--- /dev/null
+++ b/src/piklab-test/generators/sdcc_config_generator_check.h
@@ -0,0 +1,20 @@
+/***************************************************************************
+ * Copyright (C) 2007 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#ifndef SDCC_CONFIG_GENERATOR_CHECK_H
+#define SDCC_CONFIG_GENERATOR_CHECK_H
+
+#include "piklab-test/base/generator_check.h"
+
+class SDCCConfigGeneratorCheck : public ConfigGeneratorCheck
+{
+public:
+ SDCCConfigGeneratorCheck() : ConfigGeneratorCheck(new SDCCGeneratorCheckHelper) {}
+};
+
+#endif
diff --git a/src/piklab-test/misc/Makefile.am b/src/piklab-test/misc/Makefile.am
new file mode 100644
index 0000000..e21c3d1
--- /dev/null
+++ b/src/piklab-test/misc/Makefile.am
@@ -0,0 +1,10 @@
+INCLUDES = -I$(top_srcdir)/src $(all_includes)
+METASOURCES = AUTO
+
+noinst_PROGRAMS = misc_check
+OBJ = $(top_builddir)/src/piklab-test/base/libtest.la $(top_builddir)/src/common/cli/libcli.la \
+ $(top_builddir)/src/common/global/libglobal.la $(top_builddir)/src/common/common/libcommon.la
+misc_check_DEPENDENCIES = $(OBJ)
+misc_check_LDADD = $(OBJ) $(LIB_KIO)
+misc_check_LDFLAGS = $(all_libraries) $(KDE_RPATH)
+misc_check_SOURCES = misc_check.cpp
diff --git a/src/piklab-test/misc/misc_check.cpp b/src/piklab-test/misc/misc_check.cpp
new file mode 100644
index 0000000..3f14287
--- /dev/null
+++ b/src/piklab-test/misc/misc_check.cpp
@@ -0,0 +1,99 @@
+/***************************************************************************
+ * Copyright (C) 2007 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#include "misc_check.h"
+
+#include "common/global/purl.h"
+
+//----------------------------------------------------------------------------
+bool MiscCheck::execute()
+{
+ {
+ PURL::Url url = PURL::Url::fromPathOrUrl(QString::null);
+ if ( !url.isEmpty() ) TEST_FAILED("isEmpty");
+ TEST_PASSED;
+ }
+ {
+ PURL::Url url = PURL::Url::fromPathOrUrl("");
+ if ( !url.isEmpty() ) TEST_FAILED("isEmpty");
+ TEST_PASSED;
+ }
+ {
+ PURL::Url url = PURL::Url::fromPathOrUrl("/");
+ if ( url.isEmpty() ) TEST_FAILED("isEmpty");
+ if ( url.isRelative() ) TEST_FAILED("isRelative");
+ if ( !url.isLocal() ) TEST_FAILED("isLocal");
+ if ( url.path()!="/" ) TEST_FAILED("");
+ if ( url.filepath()!="/" ) TEST_FAILED(url.filepath());
+ if ( url.unterminatedPath()!="/" ) TEST_FAILED("");
+ if ( !url.filename().isEmpty() ) TEST_FAILED(url.filename());
+ TEST_PASSED;
+ }
+ {
+ PURL::Url url = PURL::Url::fromPathOrUrl("test");
+ if ( url.isEmpty() ) TEST_FAILED("isEmpty");
+ if ( !url.isRelative() ) TEST_FAILED("isRelative");
+ if ( !url.isLocal() ) TEST_FAILED("isLocal");
+ if ( url.filename()!="test" ) TEST_FAILED(url.filename());
+ TEST_PASSED;
+ }
+ {
+ PURL::Url url = PURL::Url::fromPathOrUrl("/test");
+ if ( url.isEmpty() ) TEST_FAILED("isEmpty");
+ if ( url.isRelative() ) TEST_FAILED("isRelative");
+ if ( !url.isLocal() ) TEST_FAILED("isLocal");
+ if ( url.path()!="/" ) TEST_FAILED("");
+ if ( url.unterminatedPath()!="/" ) TEST_FAILED("");
+ if ( url.filepath()!="/test" ) TEST_FAILED(url.filepath());
+ if ( url.filename()!="test" ) TEST_FAILED(url.filename());
+ TEST_PASSED;
+ }
+ {
+ PURL::Url url = PURL::Url::fromPathOrUrl("/test/");
+ if ( url.isEmpty() ) TEST_FAILED("isEmpty");
+ if ( url.isRelative() ) TEST_FAILED("isRelative");
+ if ( !url.isLocal() ) TEST_FAILED("isLocal");
+ if ( url.path()!="/test/" ) TEST_FAILED("");
+ if ( url.unterminatedPath()!="/test" ) TEST_FAILED("");
+ if ( url.filepath()!="/test/" ) TEST_FAILED(url.filepath());
+ if ( !url.filename().isEmpty() ) TEST_FAILED(url.filename());
+ TEST_PASSED;
+ }
+ {
+ PURL::Url url = PURL::Url::fromPathOrUrl("c:/test");
+ if ( url.isEmpty() ) TEST_FAILED("isEmpty");
+ if ( url.isRelative() ) TEST_FAILED("isRelative");
+ if ( !url.isLocal() ) TEST_FAILED("isLocal");
+ PURL::Url url2 = PURL::Url::fromPathOrUrl("c:/");
+ if ( url.path()!=url2.path() ) TEST_FAILED(url.path());
+ if ( url==url2 ) TEST_FAILED(url.path());
+ if ( url.filename()!="test" ) TEST_FAILED(url.filename());
+ TEST_PASSED;
+ }
+ {
+ PURL::Url url = PURL::Url::fromPathOrUrl("d:/test/");
+ if ( url.isEmpty() ) TEST_FAILED("isEmpty");
+ if ( url.isRelative() ) TEST_FAILED("isRelative");
+ if ( !url.isLocal() ) TEST_FAILED("isLocal");
+ if ( !url.filename().isEmpty() ) TEST_FAILED(url.filename());
+ TEST_PASSED;
+ }
+ {
+ PURL::Url url(KURL::fromPathOrURL("http://test.net/test"));
+ if ( url.isEmpty() ) TEST_FAILED("isEmpty");
+ if ( url.isRelative() ) TEST_FAILED("isRelative");
+ if ( url.isLocal() ) TEST_FAILED("isLocal");
+ if ( url.filename()!="test" ) TEST_FAILED(url.filename());
+ TEST_PASSED;
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------------
+TEST_MAIN(MiscCheck)
diff --git a/src/piklab-test/misc/misc_check.h b/src/piklab-test/misc/misc_check.h
new file mode 100644
index 0000000..a36b3cf
--- /dev/null
+++ b/src/piklab-test/misc/misc_check.h
@@ -0,0 +1,20 @@
+/***************************************************************************
+ * Copyright (C) 2007 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#ifndef MISC_CHECK_H
+#define MISC_CHECK_H
+
+#include "piklab-test/base/main_test.h"
+
+class MiscCheck : public Test
+{
+protected:
+ virtual bool execute();
+};
+
+#endif
diff --git a/src/piklab-test/save_load_memory/Makefile.am b/src/piklab-test/save_load_memory/Makefile.am
new file mode 100644
index 0000000..da9365f
--- /dev/null
+++ b/src/piklab-test/save_load_memory/Makefile.am
@@ -0,0 +1,18 @@
+INCLUDES = -I$(top_srcdir)/src $(all_includes)
+METASOURCES = AUTO
+
+noinst_PROGRAMS = save_load_memory_check
+OBJ = $(top_builddir)/src/piklab-test/base/libtest.la \
+ $(top_builddir)/src/common/cli/libcli.la \
+ $(top_builddir)/src/tools/gputils/libgputils.la \
+ $(top_builddir)/src/coff/base/libcoff.la \
+ $(top_builddir)/src/common/global/libglobal.la $(top_builddir)/src/devices/list/libdevicelistnoui.la \
+ $(top_builddir)/src/devices/pic/pic/libpic.la $(top_builddir)/src/devices/pic/base/libpicbase.la \
+ $(top_builddir)/src/devices/pic/xml_data/libpicxml.la \
+ $(top_builddir)/src/devices/mem24/mem24/libmem24.la $(top_builddir)/src/devices/mem24/base/libmem24base.la \
+ $(top_builddir)/src/devices/mem24/xml_data/libmem24xml.la \
+ $(top_builddir)/src/devices/base/libdevicebase.la $(top_builddir)/src/common/common/libcommon.la
+save_load_memory_check_DEPENDENCIES = $(OBJ)
+save_load_memory_check_LDADD = $(OBJ) $(LIB_KIO)
+save_load_memory_check_LDFLAGS = $(all_libraries) $(KDE_RPATH)
+save_load_memory_check_SOURCES = save_load_memory_check.cpp
diff --git a/src/piklab-test/save_load_memory/save_load_memory_check.cpp b/src/piklab-test/save_load_memory/save_load_memory_check.cpp
new file mode 100644
index 0000000..22eb1ea
--- /dev/null
+++ b/src/piklab-test/save_load_memory/save_load_memory_check.cpp
@@ -0,0 +1,64 @@
+/***************************************************************************
+ * Copyright (C) 2007 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#include "save_load_memory_check.h"
+
+#include "devices/base/generic_memory.h"
+#include "devices/base/device_group.h"
+
+//----------------------------------------------------------------------------
+SaveLoadMemoryCheck::SaveLoadMemoryCheck()
+ : _memory1(0), _memory2(0)
+{
+ _view = new CLI::View;
+ PURL::Url dest(PURL::Directory::current(), "test.hex");
+ _fdest = new PURL::File(dest, *_view);
+}
+
+SaveLoadMemoryCheck::~SaveLoadMemoryCheck()
+{
+ _fdest->remove();
+ delete _fdest;
+ delete _view;
+}
+
+bool SaveLoadMemoryCheck::init(const Device::Data &data)
+{
+ _memory1 = data.group().createMemory(data);
+ _memory2 = data.group().createMemory(data);
+ return true;
+}
+
+void SaveLoadMemoryCheck::cleanup(const Device::Data &)
+{
+ delete _memory1;
+ _memory1 = 0;
+ delete _memory2;
+ _memory2 = 0;
+}
+
+bool SaveLoadMemoryCheck::execute(const Device::Data &data)
+{
+ // create hex file from blank memory
+ if ( !_fdest->openForWrite() ) TEST_FAILED_RETURN("")
+ _memory1->save(_fdest->stream(), HexBuffer::IHX32);
+
+ // read hex file
+ if ( !_fdest->openForRead() ) TEST_FAILED_RETURN("")
+ QStringList errors, warnings;
+ Device::Memory::WarningTypes wtypes;
+ if ( !_memory2->load(_fdest->stream(), errors, wtypes, warnings) ) TEST_FAILED_RETURN(QString("Error loading hex file into memory %1").arg(data.name()))
+
+ // compare checksums
+ if ( _memory1->checksum()!=_memory2->checksum() ) TEST_FAILED_RETURN("Memory saved and loaded is different")
+ TEST_PASSED
+ return true;
+}
+
+//----------------------------------------------------------------------------
+TEST_MAIN(SaveLoadMemoryCheck)
diff --git a/src/piklab-test/save_load_memory/save_load_memory_check.h b/src/piklab-test/save_load_memory/save_load_memory_check.h
new file mode 100644
index 0000000..f342560
--- /dev/null
+++ b/src/piklab-test/save_load_memory/save_load_memory_check.h
@@ -0,0 +1,32 @@
+/***************************************************************************
+ * Copyright (C) 2007 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#ifndef SAVE_LOAD_MEMORY_CHECK_H
+#define SAVE_LOAD_MEMORY_CHECK_H
+
+#include "piklab-test/base/device_test.h"
+#include "common/cli/cli_log.h"
+#include "common/global/pfile.h"
+namespace Device { class Memory; }
+
+class SaveLoadMemoryCheck : public DeviceTest
+{
+public:
+ SaveLoadMemoryCheck();
+ virtual ~SaveLoadMemoryCheck();
+ virtual bool init(const Device::Data &data);
+ virtual bool execute(const Device::Data &data);
+ virtual void cleanup(const Device::Data &data);
+
+private:
+ CLI::View *_view;
+ PURL::File *_fdest;
+ Device::Memory *_memory1, *_memory2;
+};
+
+#endif