Docs: C struct style
Tests: changed waiting->wait backend
This commit is contained in:
parent
62e652bbcf
commit
3a5d156690
33 changed files with 60 additions and 37 deletions
|
|
@ -47,15 +47,14 @@ myfn(int par1,
|
||||||
ms = NULL;
|
ms = NULL;
|
||||||
```
|
```
|
||||||
Notes:
|
Notes:
|
||||||
1. the return type of the function and all qualifers on first line (`static int`)
|
1. The return type of the function and all qualifers on first line (`static int`)
|
||||||
2. function name and first parameter on second line, thereafter each parameter on own line
|
2. Function name and first parameter on second line, thereafter each parameter on own line
|
||||||
3. Each parameter indented to match the "longest" (`my_structure`)
|
3. Each parameter indented to match the "longest" (`my_structure`)
|
||||||
4. Pointer declarations written: `type *p`, not: `type* p`.
|
4. Pointer declarations written: `type *p`, not: `type* p`.
|
||||||
5. All local variables in a function declared at top of function, not inline with C-statements.
|
5. All local variables in a function declared at top of function, not inline with C-statements.
|
||||||
6. Local variables can be initialized with scalars or constants, not eg malloc or functions with return values that need to be checked for errors
|
6. Local variables can be initialized with scalars or constants, not eg malloc or functions with return values that need to be checked for errors
|
||||||
7. There is a single empty line between local variable declarations and the first function statement.
|
7. There is a single empty line between local variable declarations and the first function statement.
|
||||||
|
|
||||||
|
|
||||||
Function signatures are declared in include files or in forward declaration using "one-line" syntax, unless very long:
|
Function signatures are declared in include files or in forward declaration using "one-line" syntax, unless very long:
|
||||||
```
|
```
|
||||||
static int myfn(int par1, my_structure *par2);
|
static int myfn(int par1, my_structure *par2);
|
||||||
|
|
@ -123,6 +122,28 @@ files, there is only a single level of include file dependencies.
|
||||||
|
|
||||||
The drawback is that the same include file may need to be repeated in many .c files.
|
The drawback is that the same include file may need to be repeated in many .c files.
|
||||||
|
|
||||||
|
### Structs
|
||||||
|
|
||||||
|
Struct fields should have a prefix to distinguish them from other struct fields. The prefix should use an abbreviation of the struct name.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
```
|
||||||
|
struct my_struct{
|
||||||
|
int ms_foo;
|
||||||
|
char *ms_string[42];
|
||||||
|
}
|
||||||
|
```
|
||||||
|
where `ms_` is the prefix and is an abbreviation of `my_struct`.
|
||||||
|
|
||||||
|
### Global variables
|
||||||
|
|
||||||
|
Try to avoid global variables.
|
||||||
|
|
||||||
|
If you absolutely need one, try to contain it as static within a
|
||||||
|
single C-file, ie do not declare it extern and use it elsewhere.
|
||||||
|
|
||||||
|
Also, always prepend a global variable with `_`, underscore.
|
||||||
|
|
||||||
## How to work in git
|
## How to work in git
|
||||||
|
|
||||||
Clixon uses semantic versioning (https://semver.org).
|
Clixon uses semantic versioning (https://semver.org).
|
||||||
|
|
|
||||||
|
|
@ -228,7 +228,7 @@ if [ $BE -ne 0 ]; then
|
||||||
start_backend -s init -f $cfg
|
start_backend -s init -f $cfg
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
if [ $RC -ne 0 ]; then
|
if [ $RC -ne 0 ]; then
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,8 @@ if [ $BE -ne 0 ]; then
|
||||||
new "start backend -s init -f $cfg -- -sS $fstate"
|
new "start backend -s init -f $cfg -- -sS $fstate"
|
||||||
start_backend -s init -f $cfg -- -sS $fstate
|
start_backend -s init -f $cfg -- -sS $fstate
|
||||||
fi
|
fi
|
||||||
new "waiting"
|
|
||||||
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
#-----------------------------
|
#-----------------------------
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,8 @@ if [ $BE -ne 0 ]; then
|
||||||
new "start backend -s init -f $cfg"
|
new "start backend -s init -f $cfg"
|
||||||
start_backend -s init -f $cfg
|
start_backend -s init -f $cfg
|
||||||
fi
|
fi
|
||||||
new "waiting"
|
|
||||||
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
new "get-config empty"
|
new "get-config empty"
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,7 @@ if [ $BE -ne 0 ]; then
|
||||||
start_backend -s init -f $cfg
|
start_backend -s init -f $cfg
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
if [ $RC -ne 0 ]; then
|
if [ $RC -ne 0 ]; then
|
||||||
|
|
|
||||||
|
|
@ -197,7 +197,7 @@ if [ $BE -ne 0 ]; then
|
||||||
start_backend -s init -f $cfg
|
start_backend -s init -f $cfg
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
if [ $RC -ne 0 ]; then
|
if [ $RC -ne 0 ]; then
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ if [ $BE -ne 0 ]; then
|
||||||
start_backend -s init -f $cfg
|
start_backend -s init -f $cfg
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
new "cli set t1-con t1-con t1-a 123"
|
new "cli set t1-con t1-con t1-a 123"
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,7 @@ if [ $BE -ne 0 ]; then
|
||||||
start_backend -s init -f $cfg
|
start_backend -s init -f $cfg
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
if [ $RC -ne 0 ]; then
|
if [ $RC -ne 0 ]; then
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ EOF
|
||||||
start_backend -s init -f $cfg
|
start_backend -s init -f $cfg
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
# First push in nacm rules via regular means
|
# First push in nacm rules via regular means
|
||||||
|
|
|
||||||
|
|
@ -226,7 +226,7 @@ if [ $BE -ne 0 ]; then
|
||||||
start_backend -s init -f $cfg
|
start_backend -s init -f $cfg
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
if [ $RC -ne 0 ]; then
|
if [ $RC -ne 0 ]; then
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ if [ $BE -ne 0 ]; then
|
||||||
start_backend -s startup -f $cfg
|
start_backend -s startup -f $cfg
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
if [ $RC -ne 0 ]; then
|
if [ $RC -ne 0 ]; then
|
||||||
|
|
|
||||||
|
|
@ -231,7 +231,7 @@ if [ $BE -ne 0 ]; then
|
||||||
start_backend -s init -f $cfg
|
start_backend -s init -f $cfg
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
if [ $RC -ne 0 ]; then
|
if [ $RC -ne 0 ]; then
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,7 @@ if [ $BE -ne 0 ]; then
|
||||||
start_backend -s init -f $cfg
|
start_backend -s init -f $cfg
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
if [ $RC -ne 0 ]; then
|
if [ $RC -ne 0 ]; then
|
||||||
|
|
|
||||||
|
|
@ -191,7 +191,7 @@ if [ $BE -ne 0 ]; then
|
||||||
start_backend -s init -f $cfg -- -s
|
start_backend -s init -f $cfg -- -s
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
if [ $RC -ne 0 ]; then
|
if [ $RC -ne 0 ]; then
|
||||||
|
|
|
||||||
|
|
@ -184,7 +184,7 @@ if [ $BE -ne 0 ]; then
|
||||||
start_backend -s init -f $cfg -- -s
|
start_backend -s init -f $cfg -- -s
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
if [ $RC -ne 0 ]; then
|
if [ $RC -ne 0 ]; then
|
||||||
|
|
|
||||||
|
|
@ -145,7 +145,7 @@ if [ $BE -ne 0 ]; then
|
||||||
start_backend -s init -f $cfg
|
start_backend -s init -f $cfg
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
if [ $RC -ne 0 ]; then
|
if [ $RC -ne 0 ]; then
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ if [ $BE -ne 0 ]; then
|
||||||
start_backend -s init -f $cfg
|
start_backend -s init -f $cfg
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
new "Add two entries"
|
new "Add two entries"
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ if [ $BE -ne 0 ]; then
|
||||||
start_backend -s init -f $cfg -- -n # create example notification stream
|
start_backend -s init -f $cfg -- -n # create example notification stream
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ if [ $BE -ne 0 ]; then
|
||||||
start_backend -s startup -f $cfg
|
start_backend -s startup -f $cfg
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
new "get startup"
|
new "get startup"
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ if [ $BE -ne 0 ]; then
|
||||||
start_backend -s init -f $cfg -- -s
|
start_backend -s init -f $cfg -- -s
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
new "generate config with $perfnr list entries"
|
new "generate config with $perfnr list entries"
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ function testrun(){
|
||||||
start_backend -s startup -f $cfg
|
start_backend -s startup -f $cfg
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
pid=$(cat $pidfile)
|
pid=$(cat $pidfile)
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ if [ $BE -ne 0 ]; then
|
||||||
start_backend -s init -f $cfg -- -s
|
start_backend -s init -f $cfg -- -s
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
# Check this later with committed data
|
# Check this later with committed data
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ if [ $BE -ne 0 ]; then
|
||||||
start_backend -s init -f $cfg -- -s
|
start_backend -s init -f $cfg -- -s
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
if [ $RC -ne 0 ]; then
|
if [ $RC -ne 0 ]; then
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,7 @@ if [ $BE -ne 0 ]; then
|
||||||
start_backend -s init -f $cfg -- -s
|
start_backend -s init -f $cfg -- -s
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
if [ $RC -ne 0 ]; then
|
if [ $RC -ne 0 ]; then
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ function testrun(){
|
||||||
err 1 $c
|
err 1 $c
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
if [ $expecterr -eq 1 ]; then
|
if [ $expecterr -eq 1 ]; then
|
||||||
|
|
|
||||||
|
|
@ -149,7 +149,7 @@ if [ $BE -ne 0 ]; then
|
||||||
start_backend -s init -f $cfg -- -n # create example notification stream
|
start_backend -s init -f $cfg -- -n # create example notification stream
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
if [ $RC -ne 0 ]; then
|
if [ $RC -ne 0 ]; then
|
||||||
|
|
|
||||||
|
|
@ -196,7 +196,7 @@ if [ $BE -ne 0 ]; then
|
||||||
start_backend -s init -f $cfg
|
start_backend -s init -f $cfg
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
if [ $RC -ne 0 ]; then
|
if [ $RC -ne 0 ]; then
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ function testrun(){
|
||||||
new "start backend -f $cfg -s $mode -c $dir/extra_db"
|
new "start backend -f $cfg -s $mode -c $dir/extra_db"
|
||||||
start_backend -s $mode -f $cfg -c $dir/extra_db
|
start_backend -s $mode -f $cfg -c $dir/extra_db
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
else
|
else
|
||||||
new "Restart backend as eg follows: -Ff $cfg -s $mode -c $dir/extra_db # $BETIMEOUT s"
|
new "Restart backend as eg follows: -Ff $cfg -s $mode -c $dir/extra_db # $BETIMEOUT s"
|
||||||
|
|
|
||||||
|
|
@ -258,7 +258,7 @@ if [ $BE -ne 0 ]; then
|
||||||
start_backend -s $mode -f $cfg
|
start_backend -s $mode -f $cfg
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
new "Check running db content"
|
new "Check running db content"
|
||||||
|
|
|
||||||
|
|
@ -271,7 +271,7 @@ function testrun(){
|
||||||
start_backend -s startup -f $cfg -- -u
|
start_backend -s startup -f $cfg -- -u
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
new "Check running db content"
|
new "Check running db content"
|
||||||
|
|
|
||||||
|
|
@ -268,7 +268,7 @@ function testrun(){
|
||||||
start_backend -s startup -f $cfg -- -u
|
start_backend -s startup -f $cfg -- -u
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
new "Check running db content"
|
new "Check running db content"
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ if [ $BE -ne 0 ]; then
|
||||||
start_backend -s $mode -f $cfg
|
start_backend -s $mode -f $cfg
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "waiting"
|
new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
new "Check running db content is failsafe"
|
new "Check running db content is failsafe"
|
||||||
|
|
|
||||||
|
|
@ -111,11 +111,11 @@ EOF
|
||||||
if [ $BE -ne 0 ]; then
|
if [ $BE -ne 0 ]; then
|
||||||
new "start backend -s running -f $cfg"
|
new "start backend -s running -f $cfg"
|
||||||
start_backend -s running -f $cfg
|
start_backend -s running -f $cfg
|
||||||
|
|
||||||
new "waiting"
|
|
||||||
wait_backend
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
new "wait backend"
|
||||||
|
wait_backend
|
||||||
|
|
||||||
new "netconf get config"
|
new "netconf get config"
|
||||||
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><get-config><source><candidate/></source></get-config></rpc>" "" "<rpc-reply $DEFAULTNS><data><hello xmlns=\"urn:example:simple\"><world/></hello></data></rpc-reply>"
|
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><get-config><source><candidate/></source></get-config></rpc>" "" "<rpc-reply $DEFAULTNS><data><hello xmlns=\"urn:example:simple\"><world/></hello></data></rpc-reply>"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue