Couverture des tests

ForgeIEC est protege par une suite de tests automatises complete. Chaque commit est verifie avant le merge par 117 tests unitaires qui couvrent l’ensemble du vocabulaire IEC 61131-3 Structured Text, tous les blocs fonctionnels standard et le systeme de multi-tache.

Apercu des suites de tests

SuiteTestsVerifie
FStCompilerTest101Vocabulaire ST complet
FStLibraryTest8Les 132 blocs standard (FBs + FCs)
FCodeGeneratorThreadingTest8Ordonnancement multi-tache + synchronisation lock-free
Total1170 erreur

1. Vocabulaire ST (FStCompilerTest)

101 tests verifient chaque construction du langage IEC 61131-3 Structured Text prise en charge. Chaque test compile un fragment ST via le FStCompiler et verifie le code C++ genere.

1.1 Affectations

TestCode STVerifie
assignSimplea := 42;Affectation simple
assignExpressiona := b + 1;Affectation avec expression
assignExternalExtVar := 10;Acces VAR_EXTERNAL
assignGvlQualifiedGVL.ExtVar := 5;Chemin GVL qualifie

1.2 Operateurs arithmetiques

TestCode STOperateur C
arithmeticAdda := b + 1;+
arithmeticSuba := b - 1;-
arithmeticMula := b * 2;*
arithmeticDiva := b / 2;/
arithmeticModa := b MOD 3;%
arithmeticPowerc := x ** 2.0;EXPT()
arithmeticNegatea := -b;-(...)
arithmeticParenthesesa := (b + 1) * 2;Parenthesage

1.3 Operateurs de comparaison

TestCode STOperateur C
compareEqualflag := a = b;==
compareNotEqualflag := a <> b;!=
compareLessflag := a < b;<
compareGreaterflag := a > b;>
compareLessEqualflag := a <= b;<=
compareGreaterEqualflag := a >= b;>=

1.4 Operateurs booleens

TestCode STOperateur C
boolAndflag := flag AND flag;&&
boolOrflag := flag OR flag;||
boolXorflag := flag XOR flag;^
boolNotflag := NOT flag;!

1.5 Litteraux

TestCode STVerifie
literalIntegera := 12345;Entier
literalRealc := 3.14;Virgule flottante
literalBoolTrueflag := TRUE;Valeur booleenne
literalBoolFalseflag := FALSE;Valeur booleenne
literalStringtext := 'hello';Chaine de caracteres
literalTimecounter := T#500ms;Constante temporelle

1.6 Structures de controle

IF / ELSIF / ELSE / END_IF

TestVerifie
ifSimpleCondition simple
ifElseBranchement If-Else
ifElsifBranchement multiple avec ELSIF
ifNestedBlocs IF imbriques

FOR / WHILE / REPEAT

TestVerifie
forSimpleFOR idx := 0 TO 10 DO
forWithByFOR avec pas BY
whileLoopBoucle WHILE
repeatUntilBoucle REPEAT/UNTIL

CASE

TestVerifie
caseStatementCASE/OF avec plusieurs labels + switch/case/break

RETURN / EXIT

TestVerifie
returnStatementRETURN → goto __end
exitStatementEXIT dans un FOR → break

1.7 Blocs fonctionnels (appels FB)

TestVerifie
fbCallWithInputsMyTon(IN := flag, PT := T#500ms);
fbCallWithOutputAssignMyTimer(IN := flag, Q => flag); — affectation OUT =>

1.8 Acces aux tableaux

TestVerifie
arrayReadSubscripta := arr[3];
arrayWriteSubscriptarr[5] := 42;
arrayComputedIndexa := arr[idx + 1];
arrayInForLoopAcces tableau dans une boucle FOR

1.9 Conversions de type

Le compilateur reconnait le motif XXX_TO_YYY et genere des casts C ((TYPE)value), conformement a la norme IEC.

TestCode STGenere
typeConvIntToRealINT_TO_REAL(a)(REAL)a
convRealToIntREAL_TO_INT(c)(INT)c
convBoolToIntBOOL_TO_INT(flag)(INT)flag
convIntToBoolINT_TO_BOOL(a)(BOOL)a
convDintToRealDINT_TO_REAL(counter)(REAL)counter
convIntToDintINT_TO_DINT(a)(DINT)a

1.10 Acces aux membres de structure

TestVerifie
structMemberAccesspos.x := 42;data__->pos.value.x

1.11 Variables inter-taches (multi-tache)

TestVerifie
crossPrimitiveGet__GET_EXTERNAL_ATOMIC pour lecture lock-free
crossPrimitiveSet__SET_EXTERNAL_ATOMIC pour ecriture lock-free
crossStructuredGet__snap_ acces snapshot thread-local
crossStructuredMemberAccess__snap_Struct.field acces

1.12 Blocs fonctionnels standard

Chaque FB standard IEC est instancie et appele :

TestType FBVerifie
fbTonTONTemporisation a l’enclenchement
fbTofTOFTemporisation au declenchement
fbTpTPTimer d’impulsion
fbCtuCTUCompteur croissant
fbCtdCTDCompteur decroissant
fbRtrigR_TRIGFront montant
fbFtrigF_TRIGFront descendant
fbRsRSReset-dominant
fbSrSRSet-dominant

1.13 Fonctions standard

CategorieTestsFonctions
Mathematiques12ABS, SQRT, SIN, COS, TAN, ASIN, ACOS, ATAN, EXP, LN, LOG, TRUNC
Selection4SEL, LIMIT, MIN, MAX
Chaines6LEN, LEFT, RIGHT, MID, CONCAT, FIND
Decalage binaire4SHL, SHR, ROL, ROR
Conversion de type6INT_TO_REAL, REAL_TO_INT, BOOL_TO_INT, …

1.14 Cas limites

TestVerifie
complexNestedExpressionExpressions imbriquees
multipleStatementsOnSeparateLinesProgrammes multi-lignes
emptyBodyCorps POU vide
commentOnlyBodyUniquement des commentaires
caseInsensitiveKeywordsIF/if/If
caseInsensitiveVariablesCasse des variables

2. Bibliotheque standard (FStLibraryTest)

8 tests pilotes par les donnees verifient les 132 blocs de la bibliotheque standard (standard_library.sql) automatiquement.

2.1 Blocs fonctionnels (13 FBs)

TestVerifie
fbSingleInstanceChaque FB instanciable et appelable individuellement
fbDoubleInstanceDeux instances du meme type FB simultanement
fbOutputReadToutes les sorties lisibles apres l’appel

FBs couverts : SR, RS, R_TRIG, F_TRIG, CTU, CTD, CTUD, TON, TOF, TP, RTC, SEMA, RampGen

2.2 Fonctions (119 FCs)

TestVerifie
fcCallChaque FC appelable avec les parametres corrects (104 testees)
fcInExpressionValeur de retour FC utilisable dans les expressions

Categories couvertes :

  • Arithmetique : ADD, SUB, MUL, DIV, MOD, EXPT, ABS
  • Comparaison : EQ, NE, LT, GT, LE, GE
  • Trigonometrie : SIN, COS, TAN, ASIN, ACOS, ATAN, ATAN2
  • Logarithme : EXP, LN, LOG, SQRT
  • Selection : SEL, MUX, LIMIT, MIN, MAX, MOVE, CLAMP
  • Chaines : LEN, LEFT, RIGHT, MID, CONCAT, INSERT, DELETE, REPLACE, FIND
  • Decalage binaire : SHL, SHR, ROL, ROR
  • Conversion de type : 60+ fonctions de conversion (BOOL_TO_INT, INT_TO_REAL, …)
  • Extensions ForgeIEC : LERP, MAP_RANGE, HYPOT, DEG, RAD, IK_2Link, CABS, CADD, CMUL, CSUB, CARG, CCONJ, CPOLAR, CRECT

3. Multi-tache (FCodeGeneratorThreadingTest)

8 tests verifient le systeme complet d’ordonnancement multi-tache conformement a la specification de conception (MT-spec, docs/design/multi-task-scheduler.md).

TestVerifie
singleProgramDefaultTaskUn PROGRAM sans tache explicite → synthese DefaultTask, pas de threading
twoProgramsTwoTasksDeux taches → RESOURCE0_start__, Legacy-Shim config_run__, les deux threads de tache
crossPrimitiveAtomicEmissionVariable INT partagee → stockage Location std::atomic<>, __GET_EXTERNAL_ATOMIC dans le corps
crossStructuredDoubleBufferSTRUCT partage → __DBUF_[2] + thread_local __snap_ + copie Double-Buffer entree/sortie
localVarNoSyncVariable dans une seule tache → __SET_EXTERNAL normal, pas d’Atomic
conflictTwoWritersDeux taches ecrivent la meme variable → avertissement de compilation
singleProgramDefaultTaskRetrocompatibilite : les projets existants fonctionnent sans modification

Architecture multi-tache

Primary Task (Task 0)          Secondary Tasks (1..N)
    |                               |
    | config_run__()                | RESOURCE0_task_thread__()
    |   ├─ sync_in                  |   ├─ dbuf_rd (copy-in)
    |   ├─ TASK0_body__()           |   ├─ TASKn_body__()
    |   └─ sync_out                 |   └─ dbuf_wr (copy-out)
    |                               |
    | [sous bufferLock]             | [lock-free]

Mecanismes de synchronisation :

  • CrossPrimitive (BOOL, INT, REAL, …) : std::atomic<T> sur la variable Location, __GET_EXTERNAL_ATOMIC / __SET_EXTERNAL_ATOMIC dans le code du corps
  • CrossStructured (STRUCT, ARRAY, STRING) : Double-Buffer __DBUF_[2] avec index d’ecriture atomique, snapshots thread_local __snap_ pour la coherence du Set

Assurance qualite

Verification automatisee

Les tests s’executent a chaque build avec -DBUILD_TESTS=ON. L’integration dans le pipeline CI (Forgejo Actions) est preparee.

Tests pilotes par les donnees

Les tests de bibliotheque (FStLibraryTest) lisent les definitions de blocs directement depuis standard_library.sql. Lorsque de nouveaux blocs sont ajoutes, ils sont automatiquement testes — aucune creation manuelle de cas de test necessaire.

Completude

La suite de tests couvre l’ensemble du vocabulaire IEC 61131-3 Structured Text tel que pris en charge par ForgeIEC :

  • Tous les operateurs (arithmetiques, comparaison, booleens, decalage binaire)
  • Toutes les structures de controle (IF, FOR, WHILE, REPEAT, CASE)
  • Tous les types de litteraux (Integer, Real, Bool, String, Time)
  • Tous les FBs et FCs standard (132 blocs)
  • Acces aux tableaux et structures
  • Variables qualifiees GVL
  • Synchronisation inter-taches (Atomics + Double-Buffer)
  • Conversions de type (generation de casts C)