From 661b39638fd0338b0cade9fa99d8103b54773989 Mon Sep 17 00:00:00 2001 From: Joseph Poirier Date: Thu, 17 Dec 2015 08:11:55 -0600 Subject: [PATCH] moc test dev updates --- moc_test/Makefile | 3 +-- moc_test/main.go | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/moc_test/Makefile b/moc_test/Makefile index 62c2e84..dcb0968 100644 --- a/moc_test/Makefile +++ b/moc_test/Makefile @@ -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 diff --git a/moc_test/main.go b/moc_test/main.go index 4f30974..7e6c5ad 100644 --- a/moc_test/main.go +++ b/moc_test/main.go @@ -7,11 +7,15 @@ package main import ( + "fmt" "log" rtl "./gortlsdr" ) +var passed int +var failed int + func GetDeviceCount() int { return rtl.GetDeviceCount() } @@ -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) } } @@ -69,16 +77,20 @@ 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) } } @@ -86,16 +98,20 @@ func GetCenterFreq(d *rtl.Context, i int) { 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) } } @@ -104,16 +120,20 @@ 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) } } @@ -121,8 +141,10 @@ func GetTunerGains(d *rtl.Context, i int) { 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) } } @@ -130,8 +152,10 @@ func SetTunerGain(d *rtl.Context, i int) { 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) } } @@ -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) } } @@ -152,8 +178,10 @@ 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) } } @@ -161,8 +189,10 @@ func SetTunerIfGain(d *rtl.Context, i int) { 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) } } @@ -170,16 +200,20 @@ func SetTunerGainMode(d *rtl.Context, i int) { 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) } } @@ -187,8 +221,10 @@ func GetSampleRate(d *rtl.Context, i int) { 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) } } @@ -196,8 +232,10 @@ func SetTestMode(d *rtl.Context, i int) { 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) } } @@ -205,16 +243,20 @@ func SetAgcMode(d *rtl.Context, i int) { 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) } } @@ -222,16 +264,20 @@ func GetDirectSampling(d *rtl.Context, i int) { 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) } } @@ -265,23 +311,29 @@ 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) } } @@ -289,8 +341,10 @@ func main() { 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) } @@ -298,30 +352,37 @@ func main() { 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 { @@ -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) } @@ -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) }