Fundamentals related to a bash builtin command named “test”

ABOUT test

test provides no output, but returns 0 for "true" (test successful) and 1 for "false" (test failed).

RELATED COMMAND LINE EXPOSURE
[bash]
$num=10; if (test $num -gt 5); then echo "yes"; else echo "no"; fi
yes
$num=1; if (test $num -gt 5); then echo "yes"; else echo "no"; fi
no
$num=5; if (test $num -gt 5); then echo "yes"; else echo "no"; fi
no
$

[/bash]
LINK
https://www.computerhope.com/unix/bash/test.htm

file — determine file type

commandline session

$ls
faq  favicon.ico  index.html  kernel.css  mirrors  pub	robots.txt
$file kernel.css
kernel.css: ASCII text
$file -l | head
Set 0:
Binary patterns:
Text patterns:
Set 1:
Binary patterns:
Text patterns:
Set 0:
Binary patterns:
Strength = 340 : sc68 Atari ST music []
Strength = 340 : T64 tape Image []
$file -l | tail
Strength =  28 : exported SGML document text []
Strength =  20 : Java source [text/x-java]
Strength =  20 : script text executable []
Strength =  18 : a []
Strength =  17 : a []
Strength =  12 : Perl5 module source text []
Strength =   2 : Tcl script []
Set 1:
Binary patterns:
Text patterns:
$



Linux KERNEL TESTING signaltest

ABOUT Signal(IPC)

Signals are a limited form of inter-process communication (IPC), typically used in Unix, Unix-like, and other POSIX-compliant operating systems. A signal is an asynchronous notification sent to a process or to a specific thread within the same process in order to notify it of an event that occurred. Signals originated in 1970s Bell Labs Unix and have been more recently specified in the POSIX standard.

When a signal is sent, the operating system interrupts the target process' normal flow of execution to deliver the signal. Execution can be interrupted during any non-atomic instruction. If the process has previously registered a signal handler, that routine is executed. Otherwise, the default signal handler is executed.

TYPICAL COMMANDLINE SESSION
[bash]
$sudo ./signaltest –help
signaltest V 0.85
Usage:
signaltest <options>

-b USEC –breaktrace=USEC send break trace command when latency > USEC
-l LOOPS –loops=LOOPS number of loops: default=0(endless)
-p PRIO –prio=PRIO priority of highest prio thread
-q –quiet print only a summary on exit
-t NUM –threads=NUM number of threads: default=2
-m –mlockall lock current and future memory allocations
-v –verbose output values on stdout for statistics
format: n:c:v n=tasknum c=count v=value in us

$sudo ./signaltest -v -t 10 -l 10
0: 0: 0
0: 1: 118
0: 2: 91
0: 3: 83
0: 4: 80
0: 5: 78
0: 6: 78
0: 7: 80
0: 8: 78
0: 9: 79
$

[/bash]
LINK
https://en.wikipedia.org/wiki/Signal_(IPC)
https://www.ibm.com/developerworks/community/blogs/aimsupport/entry/Finding_the_source_of_signals_on_Linux_with_strace_auditd_or_Systemtap?lang=en

test instruction +

| GDB shows TEST instruction |


Dump of assembler code for function *__GI___poll:
   0x00007f73ec2120b0 :	sub    $0x28,%rsp
   0x00007f73ec2120b4 :	mov    0x29c52e(%rip),%eax        # 0x7f73ec4ae5e8 
   0x00007f73ec2120ba :	test   %eax,%eax
   0x00007f73ec2120bc :	jne    0x7f73ec2120d5 
   0x00007f73ec2120be :	movslq %edx,%rdx
   0x00007f73ec2120c1 :	mov    $0x7,%eax
   0x00007f73ec2120c6 :	syscall
   0x00007f73ec2120c8 :	cmp    $0xfffffffffffff000,%rax
   0x00007f73ec2120ce :	ja     0x7f73ec212121 
   0x00007f73ec2120d0 :	add    $0x28,%rsp
   0x00007f73ec2120d4 :	retq
   0x00007f73ec2120d5 :	mov    %edx,0x8(%rsp)
   0x00007f73ec2120d9 :	mov    %rsi,0x10(%rsp)
   0x00007f73ec2120de :	mov    %rdi,0x18(%rsp)
   0x00007f73ec2120e3 :	callq  0x7f73ec229b50 
   0x00007f73ec2120e8 :	mov    0x8(%rsp),%edx
   0x00007f73ec2120ec :	mov    %eax,%r8d
   0x00007f73ec2120ef :	mov    0x10(%rsp),%rsi
   0x00007f73ec2120f4 :	mov    0x18(%rsp),%rdi
   0x00007f73ec2120f9 :	mov    $0x7,%eax
   0x00007f73ec2120fe :	movslq %edx,%rdx
   0x00007f73ec212101 :	syscall

test %eax,%eax

Process Invovled

Downloading Using a Torrent File.

file:     gnewsense-livecd-deltah-i386-2.3.iso                                                                              |
| size:     643,176,448 (613.38 MiB)                                                                                          |
| dest:     /home/jeffrin/Downloads/gnewsense-livecd-deltah-i386-2.3.iso                                                      |
| progress: ##_______________________________________________________________________________________________________________ |
| status:   finishing in 1:32:50 (1.9%)                                                                                       |
| dl speed: 112.3 KB/s                                                                                                        |
| ul speed: 0.0 KB/s                                                                                                          |
| sharing:  0.000  (0.0 MB up / 11.8 MB down)                                                                                 |
| seeds:    11 seen now, plus 0.018 distributed copies                                                                        |
| peers:    0 seen now, 0.0% done at 1382.9 kB/s

Explanation

In the x86 assembly language, the TEST instruction performs a bitwise
AND on two operands. The flags SF, ZF, PF, CF, OF and AF are modified
while the result of the AND is discarded. There are 9 different opcodes
for the TEST instruction depending on the type and size of the
operands. It can compare 8bit, 16bit or 32bit values. It can also
compare registers, immediate values and register indirect values.[1]

source : http://en.wikipedia.org/wiki/TEST_(x86_instruction)