Skip to content

Commit

Permalink
Som devel 20 (#70)
Browse files Browse the repository at this point in the history
* play(...)

* established getn<N>

* premake: lib by cfg

* getn template

* mainly: ComName -> ComAddr

* bullseye coverage macros incl. B() whitch works

* minimal corrections

* update sompy / gitHooks

* moved submodules

* bullseye scripts

* progress

* E_Select

* interim

* interim

* gcc & vs running; todo: remove redundant luas

* interim

* bullseye ok; to other scripts

* progress; to ci scripts

* shoud work; toto: md rework

* ci fix
  • Loading branch information
sorgom authored Nov 14, 2024
1 parent 37ec37b commit 90444e1
Show file tree
Hide file tree
Showing 82 changed files with 1,282 additions and 1,577 deletions.
8 changes: 4 additions & 4 deletions .gitHooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ fi
cd $(git rev-parse --show-toplevel)

# path to sompy python scripts
sompy=$(pwd)/sompy/somutil
sompy=$(pwd)/submodules/sompy/somutil

mdjs=
svgs=
# files regarded as text files to be cleaned
txts=
# extensions of text files sorted by likeliness
xtxt="h cpp cmd py md"
xtxt="h cpp cmd py md lua"

for file in `git diff-index --cached --name-only HEAD`; do
for file in $(git diff-index --cached --name-only HEAD); do
if [[ -f $file ]]
then
if [[ $file == *.mdj ]]; then mdjs="$mdjs $file"
Expand All @@ -45,6 +45,6 @@ if [[ -n $svgs ]]; then
fi
if [[ -n $txts ]]; then
echo cleaning text files
$py $sompy/cleanTxt.py $txts
$py $sompy/cleanTxt.py -l $txts
fi
for file in $mdjs $svgs $txts; do git add $file; done
2 changes: 0 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# all text files unix line endings
* text=auto eol=lf

*.cmd eol=crlf
*.bat eol=crlf
*.svg text eol=lf
*.mdj text eol=lf
10 changes: 5 additions & 5 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# continuous integration setup
# ============================================================
# created by Manfred Sorgo
name: C/C++ CI
name: DSTW CI

on:
push:
Expand All @@ -22,14 +22,14 @@ jobs:
submodules: 'true'

- name: build and run all
run: chmod 755 make/*.sh; make/build.sh -cr

- name: check coverage
run: make/runGcov.sh
run: chmod 755 make/*.sh; make/buildAndRun.sh

- name: run system tests
run: make/runSystemTests.sh

- name: check coverage
run: make/runGcov.sh

# - name: check env
# run: make/checkEnv.sh

5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,7 @@
*.app

# premake / build
Makefile
build
bin
obj
lib
exe
.vs
*.vcxproj.*
*.vcxproj
Expand Down
10 changes: 7 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
[submodule "cpputest"]
path = cpputest
path = submodules/cpputest
url = [email protected]:cpputest/cpputest.git
[submodule "CppUTestSteps"]
path = CppUTestSteps
path = submodules/CppUTestSteps
url = [email protected]:sorgom/CppUTestSteps.git
branch = dev
[submodule "sompy"]
path = sompy
path = submodules/sompy
url = [email protected]:sorgom/sompy.git
branch = dev
[submodule "sombin"]
path = submodules/sombin
url = [email protected]:sorgom/sombin.git
branch = dev
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
// ============================================================
// name, component, position
// addr, component, position
// ============================================================
// created by Manfred Sorgo

#pragma once
#ifndef NCPINDEX_H
#define NCPINDEX_H
#ifndef ACPINDEX_H
#define ACPINDEX_H

#include <BAS/coding.h>
#include <BAS/Containers.h>
#include <ifs/DataTypes.h>

#include <codebase/packBegin.h>

struct Ncp
struct Acp
{
const ComName name;
const ComAddr addr;
const UINT8 comp;
const size_t pos;
inline Ncp(
const ComName& name,
inline Acp(
const ComAddr& addr,
UINT8 comp = 0,
size_t pos = 0
):
name(name),
addr(addr),
comp(comp),
pos(pos)
{}
NOCOPY(Ncp)
NOCOPY(Acp)
};

#include <codebase/packEnd.h>

// ============================================================
// class NcpIndex is the core of Dispatcher
// class AcpIndex is the core of Dispatcher
// see interface I_Dispatcher
// ============================================================
class NcpIndex : public Index<const ComName&, Ncp>
class AcpIndex : public Index<const ComAddr&, Acp>
{
public:
inline NcpIndex() = default;
NOCOPY(NcpIndex)
inline AcpIndex() = default;
NOCOPY(AcpIndex)

protected:
inline const ComName& getKey(const Ncp& ncp) const final
inline const ComAddr& getKey(const Acp& acp) const final
{
return ncp.name;
return acp.addr;
}
};
#endif // _H
28 changes: 28 additions & 0 deletions application/components/BAS/coverage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// coverage instrumentation exception handling
// > works with compilers
// that support _Pragma(string-literal) directive
// - documented for:
// - gcc : https://gcc.gnu.org/onlinedocs/cpp/Pragmas.html
// - msvc: https://learn.microsoft.com/en-us/cpp/preprocessor/pragma-directives-and-the-pragma-keyword

// created by Manfred Sorgo
#pragma once
#ifndef COVERAGE_H
#define COVERAGE_H

// bullseye coverage
#if _BullseyeCoverage
// pause coverage instrumentation
#define COVERAGE_PAUSE _Pragma("BullseyeCoverage off")
// resume coverage instrumentation
#define COVERAGE_RESUME _Pragma("BullseyeCoverage on")
// force coverage of simple boolean expressions
// by converting them to ternary expressions
#define B(SIMPLE_EXPR) (SIMPLE_EXPR ? true : false)
#else
#define COVERAGE_PAUSE
#define COVERAGE_RESUME
#define B(SIMPLE_EXPR) SIMPLE_EXPR
#endif

#endif // _H
2 changes: 1 addition & 1 deletion application/components/BAS/src/BAS_Provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void BAS_Provider::load(const ProjItem* data, const UINT32 num)
bool ok = true;
for (UINT32 n = 0; ok and (n < num); ++n, ++data)
{
const PosRes res = IL::getDispatcher().assign(data->name, comp(), n);
const PosRes res = IL::getDispatcher().assign(data->addr, comp(), n);
ok = res.valid and add(res.pos, *data);
}
if (not ok)
Expand Down
29 changes: 29 additions & 0 deletions application/components/BAS/utilz.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// ============================================================
// misc utilities
// ============================================================
// created by Manfred Sorgo
#pragma once
#ifndef UTILZ_H
#define UTILZ_H

#include <codebase/BaseTypes.h>

template <size_t N>
using data_tn = UINT8[N];

// get byte subset of an object
template <class T, size_t N, size_t P=0>
inline const data_tn<N>& getn(const T& obj)
{
static_assert(P + N <= sizeof(T));
return *(reinterpret_cast<const data_tn<N>*>(&obj) + P);
}

// get byte subset of ComData
template <size_t N, size_t P=0>
inline const data_tn<N>& getn(const ComData& obj)
{
return getn<ComData, N, P>(obj);
}

#endif // _H
2 changes: 1 addition & 1 deletion application/components/COM/TCP.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TCP : public I_TCP

bool listen(INT32 socket) const;

INT32 select(INT32 socket) const;
E_Select select(INT32 socket) const;

INT32 accept(INT32 socket) const;

Expand Down
18 changes: 14 additions & 4 deletions application/components/COM/src/TCP.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <COM/TCP.h>
#include <BAS/coverage.h>

#ifdef _WIN32
#include <winsock2.h>
Expand Down Expand Up @@ -53,22 +54,31 @@ bool TCP::listen(const INT32 socket) const
return ::listen(socket, SOMAXCONN) >= 0;
}

INT32 TCP::select(const INT32 socket) const
E_Select TCP::select(const INT32 socket) const
{
fd_set readfds;
#ifdef _WIN32
#pragma warning(disable:4389)
#endif
// interns of fd_set macros must not be coverage instrumented
COVERAGE_PAUSE
FD_ZERO(&readfds);
FD_SET(socket, &readfds);
COVERAGE_RESUME
#ifdef _WIN32
#pragma warning(default:4389)
#endif
timeval timeout;
timeout.tv_sec = mSec;
timeout.tv_usec = mMicro;
INT32 ret = 0;
E_Select ret = SELECT_NONE;
if (::select(socket + 1, &readfds, nullptr, nullptr, &timeout) < 0)
{
ret = -1;
ret = SELECT_ERR;
}
else if (FD_ISSET(socket, &readfds))
{
ret = 1;
ret = SELECT_READY;
}
return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion application/components/COM/src/TCP_Com.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <COM/TCP_Com.h>
#include <SYS/IL.h>
#include <BAS/coverage.h>

using std::endl;

Expand Down Expand Up @@ -78,7 +79,6 @@ I_TCP_Con& TCP_Listener_Ctrl::getCon() const
}
INSTANCE_DEF(TCP_Listener_Ctrl)


// ============================================================
// TCP connections
// ============================================================
Expand Down
4 changes: 2 additions & 2 deletions application/components/LCR/src/LCR_X.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <LCR/LCR_X.h>
#include <SYS/IL.h>
#include <BAS/utilz.h>

void LCR_X::open()
{
Expand Down Expand Up @@ -107,8 +108,7 @@ bool LCR_UBK::validUbk(const UINT8 state)

void LCR_UBK::fromFld(const ComData& data)
{
const auto state = data.param1;
const auto ubk = data.param2;
const auto [state, ubk] = getn<2>(data);
if (
(
(state != mStateToGui) or
Expand Down
9 changes: 5 additions & 4 deletions application/components/SIG/src/SIG_X.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <SIG/SIG_X.h>
#include <SYS/IL.h>
#include <BAS/utilz.h>

void SIG_X::procFromFld(const UINT8 state)
{
Expand Down Expand Up @@ -152,7 +153,7 @@ void SIG_H::proc_H1()

void SIG_N::fromFld(const ComData& data)
{
const auto state = data.param1, speed = data.param2;
const auto [ state, speed ] = getn<2>(data);
switch (state)
{
case SIG_STATE_UNDEF:
Expand All @@ -169,7 +170,7 @@ void SIG_N::fromFld(const ComData& data)

void SIG_N::fromGui(const ComData& data)
{
const auto state = data.param1, speed = data.param2;
const auto [ state, speed ] = getn<2>(data);
switch (state)
{
case SIG_STATE_N0:
Expand Down Expand Up @@ -216,7 +217,7 @@ void SIG_N::proc_N1(const UINT8 speed)

void SIG_H_N::fromFld(const ComData& data)
{
const auto state = data.param1, speed = data.param2;
const auto [ state, speed ] = getn<2>(data);
switch (state)
{
case SIG_STATE_UNDEF:
Expand All @@ -235,7 +236,7 @@ void SIG_H_N::fromFld(const ComData& data)

void SIG_H_N::fromGui(const ComData& data)
{
const auto state = data.param1, speed = data.param2;
const auto [ state, speed ] = getn<2>(data);
switch (state)
{
case SIG_STATE_H0_N0:
Expand Down
10 changes: 5 additions & 5 deletions application/components/SYS/Dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define DISPATCHER_H

#include <BAS/coding.h>
#include <BAS/NcpIndex.h>
#include <BAS/AcpIndex.h>
#include <ifs/I_Dispatcher.h>
#include <ifs/I_Provider.h>

Expand All @@ -18,7 +18,7 @@ class Dispatcher : public I_Dispatcher
void clear() override;
void index() override;

const PosRes assign(const ComName& name, E_Comp comp, size_t pos) override;
const PosRes assign(const ComAddr& addr, E_Comp comp, size_t pos) override;

void fromFld(const ComTele& tele) const override;
void fromGui(const ComTele& tele) const override;
Expand All @@ -33,10 +33,10 @@ class Dispatcher : public I_Dispatcher
NOCOPY(Dispatcher)

private:
NcpIndex mIndx;
AcpIndex mIndx;
inline Dispatcher() = default;
static void forwardFld(I_Provider& prov, const Ncp& ncp, const ComTele& tele);
static void forwardGui(I_Provider& prov, const Ncp& ncp, const ComTele& tele);
static void forwardFld(I_Provider& prov, const Acp& acp, const ComTele& tele);
static void forwardGui(I_Provider& prov, const Acp& acp, const ComTele& tele);
static void reGui(I_Provider& prov);
};
#endif // _H
Loading

0 comments on commit 90444e1

Please sign in to comment.