Skip to content

Commit

Permalink
moc test dev updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jpoirier committed Dec 17, 2015
1 parent 4b89863 commit 661b396
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
3 changes: 1 addition & 2 deletions moc_test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ all:
cd gortlsdr && ar rcs librtlsdr.a librtlsdr.o
cd gortlsdr && cp ../../rtlsdr.go .
cd gortlsdr && cp ../../exports.go .
cd gortlsdr && CC="gcc -DMOCK_TEST" go build --ldflags '-extldflags "-static" "-L."' -o gortlsdr.a rtlsdr.go exports.go
# cd gortlsdr && CC="gcc -Dmock" go build -o gortlsdr.a rtlsdr.go exports.go
cd gortlsdr && CC="gcc -Dmock" go build -o gortlsdr.a rtlsdr.go exports.go
go build --ldflags '-extldflags "-L./gortlsdr"' main.go
rm ./gortlsdr/rtlsdr.go ./gortlsdr/exports.go

Expand Down
68 changes: 68 additions & 0 deletions moc_test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
package main

import (
"fmt"
"log"

rtl "./gortlsdr"
)

var passed int
var failed int

func GetDeviceCount() int {
return rtl.GetDeviceCount()
}
Expand Down Expand Up @@ -40,16 +44,20 @@ func SetXtalFreq(d *rtl.Context, i int) {
rtlFreqHz := 2500000
tunerFreqHz := 5000000
if err := d.SetXtalFreq(rtlFreqHz, tunerFreqHz); err != nil {
failed++
log.Printf("--- FAILED, SetXtalFreq i:%d - %s\n", i, err)
} else {
passed++
log.Printf("--- PASSED, SetXtalFreq i:%d\n", i)
}
}

func GetXtalFreq(d *rtl.Context, i int) {
if _, _, err := d.GetXtalFreq(); err != nil {
failed++
log.Printf("--- FAILED, GetXtalFreq i:%d - %s\n", i, err)
} else {
passed++
log.Printf("--- PASSED, GetXtalFreq i:%d\n", i)
}
}
Expand All @@ -69,33 +77,41 @@ func GetXtalFreq(d *rtl.Context, i int) {
func SetCenterFreq(d *rtl.Context, i int) {
freqHz := 2500100
if err := d.SetCenterFreq(freqHz); err != nil {
failed++
log.Printf("--- FAILED, SetCenterFreq i:%d - %s\n", i, err)
} else {
passed++
log.Printf("--- PASSED, SetCenterFreq i:%d\n", i)
}
}

func GetCenterFreq(d *rtl.Context, i int) {
if freqHz := d.GetCenterFreq(); freqHz == 0 {
failed++
log.Printf("--- FAILED, GetCenterFreq i:%d - %d\n", i, freqHz)
} else {
passed++
log.Printf("--- PASSED, GetCenterFreq i:%d\n", i)
}
}

func SetFreqCorrection(d *rtl.Context, i int) {
ppm := 112
if err := d.SetFreqCorrection(ppm); err != nil {
failed++
log.Printf("--- FAILED, SetFreqCorrection i:%d - %s\n", i, err)
} else {
passed++
log.Printf("--- PASSED, SetFreqCorrection i:%d\n", i)
}
}

func GetFreqCorrection(d *rtl.Context, i int) {
if ppm := d.GetFreqCorrection(); ppm < 0 {
failed++
log.Printf("--- FAILED, GetFreqCorrection i:%d - %d\n", i, ppm)
} else {
passed++
log.Printf("--- PASSED, GetFreqCorrection i:%d\n", i)
}
}
Expand All @@ -104,34 +120,42 @@ func GetTunerType(d *rtl.Context, i int) {
tunerType := d.GetTunerType()
switch tunerType {
case "UNKNOWN", "RTLSDR_TUNER_UNKNOWN":
failed++
log.Printf("--- FAILED, GetTunerType i:%d - %s\n", i, tunerType)
default:
passed++
log.Printf("--- PASSED, GetTunerType i:%d\n", i)
}
}

func GetTunerGains(d *rtl.Context, i int) {
if _, err := d.GetTunerGains(); err != nil {
failed++
log.Printf("--- FAILED, GetTunerGains i:%d - %s\n", i, err)
} else {
passed++
log.Printf("--- PASSED, GetTunerGains i:%d\n", i)
}
}

func SetTunerGain(d *rtl.Context, i int) {
gainTenthsDb := 110
if err := d.SetTunerGain(gainTenthsDb); err != nil {
failed++
log.Printf("--- FAILED, SetTunerGain i:%d - %s\n", i, err)
} else {
passed++
log.Printf("--- PASSED, SetTunerGain i:%d\n", i)
}
}

func SetTunerBw(d *rtl.Context, i int) {
bwHz := 2300000
if err := d.SetTunerBw(bwHz); err != nil {
failed++
log.Printf("--- FAILED, SetTunerBw i:%d - %s\n", i, err)
} else {
passed++
log.Printf("--- PASSED, SetTunerBw i:%d\n", i)
}
}
Expand All @@ -142,8 +166,10 @@ func SetTunerBw(d *rtl.Context, i int) {

func GetTunerGain(d *rtl.Context, i int) {
if gainTenthsDb := d.GetTunerGain(); gainTenthsDb <= 0 {
failed++
log.Printf("--- FAILED, GetTunerGain i:%d - %d\n", i, gainTenthsDb)
} else {
passed++
log.Printf("--- PASSED, GetTunerGain i:%d\n", i)
}
}
Expand All @@ -152,86 +178,106 @@ func SetTunerIfGain(d *rtl.Context, i int) {
stage := 6 // 1 - 6
gainTenthsDb := -30
if err := d.SetTunerIfGain(stage, gainTenthsDb); err != nil {
failed++
log.Printf("--- FAILED, SetTunerIfGain i:%d - %s\n", i, err)
} else {
passed++
log.Printf("--- PASSED, SetTunerIfGain i:%d\n", i)
}
}

func SetTunerGainMode(d *rtl.Context, i int) {
manualMode := true
if err := d.SetTunerGainMode(manualMode); err != nil {
failed++
log.Printf("--- FAILED, SetTunerGainMode i:%d - %s\n", i, err)
} else {
passed++
log.Printf("--- PASSED, SetTunerGainMode i:%d\n", i)
}
}

func SetSampleRate(d *rtl.Context, i int) {
rateHz := 225001
if err := d.SetSampleRate(rateHz); err != nil {
failed++
log.Printf("--- FAILED, SetSampleRate i:%d - %s\n", i, err)
} else {
passed++
log.Printf("--- PASSED, SetSampleRate i:%d\n", i)
}
}

func GetSampleRate(d *rtl.Context, i int) {
if rateHz := d.GetSampleRate(); rateHz <= 0 {
failed++
log.Printf("--- FAILED, GetSampleRate i:%d - %d\n", i, rateHz)
} else {
passed++
log.Printf("--- PASSED, GetSampleRate i:%d\n", i)
}
}

func SetTestMode(d *rtl.Context, i int) {
testMode := false
if err := d.SetTestMode(testMode); err != nil {
failed++
log.Printf("--- FAILED, SetTestMode i:%d - %s\n", i, err)
} else {
passed++
log.Printf("--- PASSED, SetTestMode i:%d\n", i)
}
}

func SetAgcMode(d *rtl.Context, i int) {
AGCMode := true
if err := d.SetAgcMode(AGCMode); err != nil {
failed++
log.Printf("--- FAILED, SetAgcMode i:%d - %s\n", i, err)
} else {
passed++
log.Printf("--- PASSED, SetAgcMode i:%d\n", i)
}
}

func SetDirectSampling(d *rtl.Context, i int) {
mode := rtl.SamplingIADC
if err := d.SetDirectSampling(mode); err != nil {
failed++
log.Printf("--- FAILED, SetDirectSampling i:%d - %s\n", i, err)
} else {
passed++
log.Printf("--- PASSED, SetDirectSampling i:%d\n", i)
}
}

func GetDirectSampling(d *rtl.Context, i int) {
if _, err := d.GetDirectSampling(); err != nil {
failed++
log.Printf("--- FAILED, GetDirectSampling i:%d - %s\n", i, err)
} else {
passed++
log.Printf("--- PASSED, GetDirectSampling i:%d\n", i)
}
}

func SetOffsetTuning(d *rtl.Context, i int) {
enable := false
if err := d.SetOffsetTuning(enable); err != nil {
failed++
log.Printf("--- FAILED, SetOffsetTuning i:%d - %s\n", i, err)
} else {
passed++
log.Printf("--- PASSED, SetOffsetTuning i:%d\n", i)
}
}

func GetOffsetTuning(d *rtl.Context, i int) {
if _, err := d.GetOffsetTuning(); err != nil {
failed++
log.Printf("--- FAILED, GetOffsetTuning i:%d - %s\n", i, err)
} else {
passed++
log.Printf("--- PASSED, GetOffsetTuning i:%d\n", i)
}
}
Expand Down Expand Up @@ -265,63 +311,78 @@ func main() {

//---------- Device Check ----------
if cnt = GetDeviceCount(); cnt == 0 {
failed++
log.Println("--- FAILED, GetDeviceCount no devices found, exiting...")
} else {
passed++
log.Println("--- PASSED, GetDeviceCount...")
}

for i := 0; i < cnt; i++ {
if len(GetDeviceName(i)) == 0 {
failed++
log.Printf("--- FAILED, GetDeviceName i:%d\n", i)
} else {
passed++
log.Printf("--- PASSED, GetDeviceName i:%d\n", i)
}
}

for i := 3; i < 6; i++ {
if len(GetDeviceName(i)) != 0 {
failed++
log.Printf("--- FAILED, GetDeviceName i:%d\n", i)
} else {
passed++
log.Printf("--- PASSED, GetDeviceName i:%d\n", i)
}
}

serials := make([]string, 3)
for i := 0; i < cnt; i++ {
if _, _, s, err := GetDeviceUsbStrings(i); err != nil {
failed++
log.Printf("--- FAILED, GetDeviceUsbStrings i:%d, %s\n", i, err)
} else {
passed++
serials = append(serials, s)
log.Printf("--- PASSED, GetDeviceUsbStrings i:%d\n", i)
}
}

for i := 3; i < 6; i++ {
if _, _, _, err := GetDeviceUsbStrings(i); err == nil {
failed++
log.Printf("--- FAILED, GetDeviceUsbStrings i:%d, %s\n", i, err)
} else {
passed++
log.Printf("--- PASSED, GetDeviceUsbStrings i:%d\n", i)
}
}

for i, s := range serials {
if _, err := GetIndexBySerial(s); err != nil {
failed++
log.Printf("--- FAILED, GetIndexBySerial i:%d - %s\n", i, err)
} else {
passed++
log.Printf("--- PASSED, GetIndexBySerial i:%d\n", i)
}
}

for i, s := range []string{"One", "Two", "Three"} {
if _, err := GetIndexBySerial(s); err == nil {
failed++
log.Printf("--- FAILED, GetIndexBySerial i:%d - %s\n", i, err)
} else {
passed++
log.Printf("--- PASSED, GetIndexBySerial i:%d\n", i)
}
}

for i := 5; i < 10; i++ {
if d, err := rtl.Open(i); err == nil {
failed++
log.Printf("--- FAILED, Open i:%d - %s\n", i, err)
continue
} else {
Expand All @@ -335,9 +396,11 @@ func main() {
var d *rtl.Context

if d, err = rtl.Open(i); err != nil {
failed++
log.Printf("--- FAILED, Open i:%d - %s\n", i, err)
continue
} else {
passed++
log.Printf("--- PASSED, Open i:%d\n", i)
}

Expand Down Expand Up @@ -391,9 +454,14 @@ func main() {
// CancelAsync(d, i)

if err = d.Close(); err != nil {
failed++
log.Printf("--- FAILED, Close %s - %s...\n", err, i)
} else {
passed++
log.Println("--- PASSED, Close...")
}
}

fmt.Printf("\n--- PASSED: %d\n", passed)
fmt.Printf("--- FAILED: %d\n", failed)
}

0 comments on commit 661b396

Please sign in to comment.