Outils pour utilisateurs

Outils du site


blog

Go lang - goroutines

Pb sortie de main avant terminaisons des goroutines - Attendre la fin de toutes les goroutines avant de terminer le programme (la fonction main)

Afficher les résultats des goroutine de la plus rapide à la plus longue

Voir :

        ch1 := make(chan int)
        ch2 := make(chan int)
        go evenSum(1, 10, ch1)
        go squareSum(1, 10, ch2)
        for range 2 {
                select {
                case r1 := <-ch1:
                        fmt.Println(r1)
                case r2 := <-ch2:
                        fmt.Println(r2)
                }
        }

FIXME

2026/05/06 22:58 · Jean-Baptiste

Notes code dev - qualité de code - bonnes pratiques - sécu

Voir :

Points:

  • Testing
  • Negative testing (tests that should cause failures)
  • Detect and check unreachable code, e.g., via warning flags (static analysis)
  • Forbid misleading indentation (static analysis)
  • Detect duplicate lines in source code (static analysis)
  • Make access failure the default (static analysis)
  • Make your methods do only one thing
  • Use readable, descriptive variable names

4 tools:

  • ASan (Address Sanitizer)
  • MSan (Memory Sanitizer)
  • UBSan (Undefined Behaviour Sanitizer)
  • Valgrind
  • fuzzing

Source : https://www.cl.cam.ac.uk/~nk480/C1819/lecture5.pdf

Autres

  • AddressSanitizer (detects addressability issues) and LeakSanitizer (detects memory leaks)
  • ThreadSanitizer (detects data races and deadlocks) for C++ and Go
  • MemorySanitizer (detects use of uninitialized memory)
  • HWASAN, or Hardware-assisted AddressSanitizer, a newer variant of AddressSanitizer that consumes much less memory UBSan, or UndefinedBehaviorSanitizer

Source : https://github.com/google/sanitizers

Ariane 5

Voir :

Nous avons :

  • Un buffer overflow
  • Une désactivation de la détection du buffer offerflow (unprotected code)
  • R6 - Aucune exception n'est levée
  • Un système redondant, mais avec le même code buggé
  • Ça n'avait pas été testé
  • R5 - Ça aurait pu être évité en rendant explicites les cas limites
The Inquiry Board's Recommendations

Source: https://www.esa.int/esapub/bulletin/bullet89/recom89.htm

The Inquiry Board's Recommendations

R1      Switch off the alignment function of the inertial reference
        system immediately after lift-off. More generally, no software
        function should run during flight unless it is needed.

R2      Prepare a test facility including as much real equipment
        as technically feasible, inject realistic input data, and perform
        complete, closed-loop, system testing. Complete simulations must
        take place before any mission. A high test coverage has to be
        obtained.

R3      Do not allow any sensor, such as the inertial reference
        system, to stop sending best-effort data.

R4      Organise, for each item of equipment incorporating
        software, a specific software qualification review. The
        Industrial Architect shall take part in these reviews and report
        on complete system testing performed with the equipment. All
        restrictions on use of the equipment shall be made explicit for
        the Review Board. Make all critical software a Configuration
        Controlled Item.


R5      Review all flight software (including embedded software),
        and in particular:

    Identify all implicit assumptions made by the code and its justification documents on the values of quantities provided by the equipment. Check these assumptions against the restrictions on use of the equipment.

    Verify the range of values taken by any internal or communication variables in the software.

    Solutions to potential problems in the onboard computer software, paying particular attention to onboard computer switchover, shall be proposed by the Project Team and reviewed by a group of external experts, who shall report to the onboard- computer Qualification Board.


R6      Wherever technically feasible, consider confining
        exceptions to tasks and devise backup capabilities.

R7      Provide more data to the telemetry upon failure of any
        component, so that recovering equipment will be less essential.

R8      Reconsider the definition of critical components, taking
        failures of software origin into account (particularly single-
        point failures).

R9      Include external (to the project) participants when
        reviewing specifications, code and justification documents. Make
        sure that these reviews consider the substance of arguments,
        rather than check that verifications have been made.

R10     Include trajectory data in specifications and test
        requirements.

R11     Review the test coverage of existing equipment and extend
        it where deemed necessary.

R12     Give the justification documents the same attention as
        code. Improve the technique for keeping code and its
        justifications consistent.

R13     Set up a team that will prepare the procedure for
        qualifying software, propose stringent rules for confirming such
        qualification, and ascertain that specification, verification and
        testing of software are of a consistently high quality in the
        Ariane-5 Programme. Inclusion of external RAMS (Reliability,
        Availability, Maintainability, Safety) experts is to be
        considered.

R14     A more transparent organisation of the cooperation among
        the partners in the Ariane-5 Programme must be considered. Close
        engineering cooperation, with clear-cut authority and
        responsibility, is needed to achieve system coherence, with
        simple and clear interfaces between partners.

FIXME

2026/05/04 20:51 · Jean-Baptiste

Go lang - GUI

Par nature Go n'est pas orienté utilisateur.

L'interface graphique “naturelle” à Go est le Web (WebUI)

Cependant il est possible d'utiliser :

  • Tk9 https://pkg.go.dev/modernc.org/tk9.0 pour des applis simple et portable CGo-free il est vraiment natif Go et crossplatform
  • Qt avec https://github.com/mappu/miqt Qt est la référence
  • Wails projet prometteur, mais pas compatible pour les anciennes versions. nécessite Node (Svelte, React, Vue, Preact, Lit, Vanilla)
  • Flutter : Pour Android

Qt - miqt

package main
 
import (
        "fmt"
        "os"
 
        "github.com/mappu/miqt/qt"
)
 
func main() {
 
        qt.NewQApplication(os.Args)
 
        btn := qt.NewQPushButton3("Hello world!")
        btn.SetFixedWidth(320)
 
        var counter int = 0
 
        btn.OnPressed(func() {
                counter++
                btn.SetText(fmt.Sprintf("You have clicked the button %d time(s)", counter))
        })
 
        btn.Show()
 
        qt.QApplication_Exec()
 
        fmt.Println("OK!")
}

FIXME

2026/05/03 18:03 · Jean-Baptiste

Go lang - err compilation pour windows - crosscompilation

$ env GOOS=windows go build main.go 
# github.com/mappu/miqt/qt
../../pkg/mod/github.com/mappu/miqt@v0.13.0/qt/gen_qaccessible_64bit.go:6:33: undefined: QAccessible__RelationFlag
../../pkg/mod/github.com/mappu/miqt@v0.13.0/qt/gen_qgraphicsitem_64bit.go:6:36: undefined: QGraphicsItem__Extension
../../pkg/mod/github.com/mappu/miqt@v0.13.0/qt/gen_qnamespace_64bit.go:6:28: undefined: KeyboardModifier
../../pkg/mod/github.com/mappu/miqt@v0.13.0/qt/gen_qnamespace_64bit.go:7:21: undefined: Modifier
../../pkg/mod/github.com/mappu/miqt@v0.13.0/qt/gen_qnamespace_64bit.go:8:23: undefined: MouseButton
../../pkg/mod/github.com/mappu/miqt@v0.13.0/qt/gen_qnamespace_64bit.go:9:34: undefined: WindowType
../../pkg/mod/github.com/mappu/miqt@v0.13.0/qt/gen_qnamespace_64bit.go:10:22: undefined: InputMethodQuery
../../pkg/mod/github.com/mappu/miqt@v0.13.0/qt/gen_qnamespace_64bit.go:11:18: undefined: InputMethodQuery
../../pkg/mod/github.com/mappu/miqt@v0.13.0/qt/gen_qnamespace_64bit.go:12:29: undefined: InputMethodHint
../../pkg/mod/github.com/mappu/miqt@v0.13.0/qt/gen_qnamespace_64bit.go:13:23: undefined: GestureType
../../pkg/mod/github.com/mappu/miqt@v0.13.0/qt/gen_qnamespace_64bit.go:13:23: too many errors
$ env CGO_ENABLED=1 GOOS=windows go build main.go 
# runtime/cgo
gcc: error: unrecognized command-line option ‘-mthreads’; did you mean ‘-pthread’?
...
$ env GOOS=windows GOARCH=386 CGO_ENABLED=1 CC=i686-w64-mingw32-gcc CXX=i686-w64-mingw32-g++ CGO_LDFLAGS="-lssp" go build -ldflags="-s -w" -o app1.exe main.go                                                                                                      
github.com/mappu/miqt/qt: exec: "i686-w64-mingw32-g++": executable file not found in $PATH
...
#sudo apt-get install gcc-multilib-i686-linux-gnu
sudo apt-get install gcc-mingw-w64-bootstrap
$ env GOOS=windows GOARCH=386 CGO_ENABLED=1 CC=i686-w64-mingw32-gcc CXX=i686-w64-mingw32-g++ CGO_LDFLAGS="-lssp" go build -ldflags="-s -w" -o app1.exe main.go
...
# github.com/mappu/miqt/qt
In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/qatomic.h:41,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qrefcount.h:43,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qbytearray.h:44,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QByteArray:1,
                 from gen_qxmlstream.cpp:1:
/usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:45:12: fatal error: type_traits: No such file or directory
   45 | #  include <type_traits>
      |            ^~~~~~~~~~~~~
compilation terminated.

Test en 64 bits :

sudo apt-get install gcc-mingw-w64-x86-64-win32
sudo apt-get install g++-mingw-w64-x86-64-win32
rm /tmp/go-* -rf
go clean -cache -modcache -fuzzcache
env GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ CGO_LDFLAGS="-lssp" go build -ldflags="-s -w" -o app1.exe main.go
...
3755312453/000657.o /tmp/go-link-3755312453/000658.o /tmp/go-link-3755312453/000659.o /tmp/go-link-3755312453/000660.o /tmp/go-link-3755312453/000661.o /tmp/go-link-3755312453/000662.o /tmp/go-link-3755312453/000663.o /tmp/go-link-3755312453/000664.o /tmp/go-link-3755312453/000665.o /tmp/go-link-3755312453/000666.o /tmp/go-link-3755312453/000667.o /tmp/go-link-3755312453/000668.o /tmp/go-link-3755312453/000669.o /tmp/go-link-3755312453/000670.o /tmp/go-link-3755312453/000671.o /tmp/go-link-3755312453/000672.o /tmp/go-link-3755312453/000673.o /tmp/go-link-3755312453/000674.o /tmp/go-link-3755312453/000675.o /tmp/go-link-3755312453/000676.o /tmp/go-link-3755312453/000677.o /tmp/go-link-3755312453/000678.o /tmp/go-link-3755312453/000679.o /tmp/go-link-3755312453/000680.o /tmp/go-link-3755312453/000681.o /tmp/go-link-3755312453/000682.o /tmp/go-link-3755312453/000683.o /tmp/go-link-3755312453/000684.o /tmp/go-link-3755312453/000685.o /tmp/go-link-3755312453/000686.o /tmp/go-link-3755312453/000687.o /tmp/go-link-3755312453/000688.o /tmp/go-link-3755312453/000689.o /tmp/go-link-3755312453/000690.o -lssp -lQt5Widgets -lQt5Gui -lQt5Core -lssp -lssp -Wl,-T,/tmp/go-link-3755312453/fix_debug_gdb_scripts.ld -Wl,--start-group -lmingwex -lmingw32 -Wl,--end-group -lkernel32                                                                                                                                                                                               
/usr/bin/x86_64-w64-mingw32-ld.bfd: cannot find -lQt5Widgets: No existe el fichero o el directorio                                                                                                                
/usr/bin/x86_64-w64-mingw32-ld.bfd: cannot find -lQt5Gui: No existe el fichero o el directorio                                                                                                                    
/usr/bin/x86_64-w64-mingw32-ld.bfd: cannot find -lQt5Core: No existe el fichero o el directorio                                                                                                                   
collect2: error: ld returned 1 exit status                                                                                                                                                                        
2026/05/03 17:32 · Jean-Baptiste
blog.txt · Dernière modification : de 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki