Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions addons/intel/clock-chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ import (
"os"
"testing"

dpll "github.com/k8snetworkplumbingwg/linuxptp-daemon/pkg/dpll-netlink"
"github.com/stretchr/testify/assert"
)

func Test_ProcessProfileTbcClockChain(t *testing.T) {
_, restoreDPLLPins := setupMockDPLLPinsFromJSON("./testdata/dpll-pins.json")
dpllMock, restoreDPLLPins := setupMockDPLLPinsFromJSON("./testdata/dpll-pins.json")
defer restoreDPLLPins()
dpllMock.pins = append(dpllMock.pins,
&dpll.PinInfo{BoardLabel: "SMA2"},
&dpll.PinInfo{BoardLabel: "U.FL1"},
&dpll.PinInfo{BoardLabel: "U.FL2"},
)
restoreDelay := setupMockDelayCompensation()
defer restoreDelay()
mockPinSet, restorePinSet := setupBatchPinSetMock()
Expand Down Expand Up @@ -69,8 +75,13 @@ func Test_ProcessProfileTbcClockChain(t *testing.T) {
}

func Test_ProcessProfileTtscClockChain(t *testing.T) {
_, restoreDPLLPins := setupMockDPLLPinsFromJSON("./testdata/dpll-pins.json")
dpllMock, restoreDPLLPins := setupMockDPLLPinsFromJSON("./testdata/dpll-pins.json")
defer restoreDPLLPins()
dpllMock.pins = append(dpllMock.pins,
&dpll.PinInfo{BoardLabel: "SMA2"},
&dpll.PinInfo{BoardLabel: "U.FL1"},
&dpll.PinInfo{BoardLabel: "U.FL2"},
)
restoreDelay := setupMockDelayCompensation()
defer restoreDelay()
mockPinSet, restorePinSet := setupBatchPinSetMock()
Expand Down Expand Up @@ -120,8 +131,13 @@ func Test_ProcessProfileTtscClockChain(t *testing.T) {
}

func Test_SetPinDefaults_AllNICs(t *testing.T) {
_, restoreDPLLPins := setupMockDPLLPinsFromJSON("./testdata/dpll-pins.json")
dpllMock, restoreDPLLPins := setupMockDPLLPinsFromJSON("./testdata/dpll-pins.json")
defer restoreDPLLPins()
dpllMock.pins = append(dpllMock.pins,
&dpll.PinInfo{BoardLabel: "SMA2"},
&dpll.PinInfo{BoardLabel: "U.FL1"},
&dpll.PinInfo{BoardLabel: "U.FL2"},
)
restoreDelay := setupMockDelayCompensation()
defer restoreDelay()
mockPinSet, restorePinSet := setupBatchPinSetMock()
Expand Down
14 changes: 10 additions & 4 deletions addons/intel/e810.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,15 @@ func OnPTPConfigChangeE810(data *interface{}, nodeProfile *ptpv1.PtpProfile) err
for name, opts := range (*nodeProfile).Plugins {
if name == pluginNameE810 {
optsByteArray, _ := json.Marshal(opts)

// Validate configuration before applying
if validationErrors := ValidateE810Opts(optsByteArray); len(validationErrors) > 0 {
return fmt.Errorf("e810 plugin configuration errors: %s", strings.Join(validationErrors, "; "))
}

err = json.Unmarshal(optsByteArray, &e810Opts)
if err != nil {
glog.Error("e810 failed to unmarshal opts: " + err.Error())
return fmt.Errorf("e810 failed to unmarshal opts: %w", err)
}

allDevices := e810Opts.allDevices()
Expand All @@ -88,7 +94,7 @@ func OnPTPConfigChangeE810(data *interface{}, nodeProfile *ptpv1.PtpProfile) err
for device, frequencies := range e810Opts.DeviceFreqencies {
err = pinConfig.applyPinFrq(device, frequencies)
if err != nil {
glog.Errorf("e825 failed to set PHC frequencies for %s: %s", device, err)
return fmt.Errorf("e810 failed to set PHC frequencies for %s: %w", device, err)
}
}

Expand Down Expand Up @@ -119,7 +125,7 @@ func OnPTPConfigChangeE810(data *interface{}, nodeProfile *ptpv1.PtpProfile) err
glog.Infof("No clock chain set: Restoring any previous pin state changes")
err = clockChain.SetPinDefaults()
if err != nil {
glog.Errorf("Could not restore clockChain pin defaults: %s", err)
return fmt.Errorf("could not restore clockChain pin defaults: %s", err)
}
clockChain = &ClockChain{DpllPins: DpllPins}
err = DpllPins.FetchPins()
Expand Down Expand Up @@ -185,7 +191,7 @@ func AfterRunPTPCommandE810(data *interface{}, nodeProfile *ptpv1.PtpProfile, co
optsByteArray, _ := json.Marshal(opts)
err = json.Unmarshal(optsByteArray, &e810Opts)
if err != nil {
glog.Error("e810 failed to unmarshal opts: " + err.Error())
return fmt.Errorf("e810 failed to unmarshal opts: %w", err)
}
switch command {
case "gpspipe":
Expand Down
27 changes: 24 additions & 3 deletions addons/intel/e810_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,13 @@ func Test_initInternalDelays_BadPart(t *testing.T) {
}

func Test_ProcessProfileTGMNew(t *testing.T) {
_, restorePins := setupMockDPLLPinsFromJSON("./testdata/dpll-pins.json")
dpllMock, restorePins := setupMockDPLLPinsFromJSON("./testdata/dpll-pins.json")
defer restorePins()
dpllMock.pins = append(dpllMock.pins,
&dpll.PinInfo{BoardLabel: "SMA2"},
&dpll.PinInfo{BoardLabel: "U.FL1"},
&dpll.PinInfo{BoardLabel: "U.FL2"},
)
restoreDelay := setupMockDelayCompensation()
defer restoreDelay()
mockPinSet, restorePinSet := setupBatchPinSetMock()
Expand All @@ -97,8 +102,13 @@ func Test_ProcessProfileTGMNew(t *testing.T) {

// Test that the profile with no phase inputs is processed correctly
func Test_ProcessProfileTBCNoPhaseInputs(t *testing.T) {
_, restoreDPLLPins := setupMockDPLLPinsFromJSON("./testdata/dpll-pins.json")
dpllMock, restoreDPLLPins := setupMockDPLLPinsFromJSON("./testdata/dpll-pins.json")
defer restoreDPLLPins()
dpllMock.pins = append(dpllMock.pins,
&dpll.PinInfo{BoardLabel: "SMA2"},
&dpll.PinInfo{BoardLabel: "U.FL1"},
&dpll.PinInfo{BoardLabel: "U.FL2"},
)
restoreDelay := setupMockDelayCompensation()
defer restoreDelay()
mockPinSet, restorePinSet := setupBatchPinSetMock()
Expand Down Expand Up @@ -142,12 +152,23 @@ func Test_ProcessProfileTBCNoPhaseInputs(t *testing.T) {
}

func Test_ProcessProfileTGMOld(t *testing.T) {
_, restorePins := setupMockDPLLPinsFromJSON("./testdata/dpll-pins.json")
dpllMock, restorePins := setupMockDPLLPinsFromJSON("./testdata/dpll-pins.json")
defer restorePins()
dpllMock.pins = append(dpllMock.pins,
&dpll.PinInfo{BoardLabel: "SMA2"},
&dpll.PinInfo{BoardLabel: "U.FL1"},
&dpll.PinInfo{BoardLabel: "U.FL2"},
)
restoreDelay := setupMockDelayCompensation()
defer restoreDelay()
mockPinSet, restorePinSet := setupBatchPinSetMock()
defer restorePinSet()

// Reset clockChain so SetPinDefaults (called via the no-PhaseInputs path) uses mock DpllPins
oldClockChain := clockChain
clockChain = &ClockChain{DpllPins: DpllPins}
defer func() { clockChain = oldClockChain }()

profile, err := loadProfile("./testdata/profile-tgm-old.yaml")
assert.NoError(t, err)
p, d := E810("e810")
Expand Down
15 changes: 11 additions & 4 deletions addons/intel/e825.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ var bcDpllPeriods = frqSet{
// E825Opts is the options structure for e825 plugin
type E825Opts struct {
PluginOpts
UblxCmds UblxCmdList `json:"ublxCmds"`
Gnss GnssOptions `json:"gnss"`
EnableDefaultConfig bool `json:"enableDefaultConfig"`
UblxCmds UblxCmdList `json:"ublxCmds"`
Gnss GnssOptions `json:"gnss"`
}

// E825PluginData is the data structure for e825 plugin
Expand Down Expand Up @@ -79,9 +80,15 @@ func OnPTPConfigChangeE825(data *interface{}, nodeProfile *ptpv1.PtpProfile) err
if name == pluginNameE825 {
// Parse user-specified config
optsByteArray, _ = json.Marshal(opts)

// Validate configuration before applying
if validationErrors := ValidateE825Opts(optsByteArray); len(validationErrors) > 0 {
return fmt.Errorf("e825 plugin configuration errors: %s", strings.Join(validationErrors, "; "))
}

err = json.Unmarshal(optsByteArray, &e825Opts)
if err != nil {
glog.Error("e825 failed to unmarshal opts: " + err.Error())
return fmt.Errorf("e825 failed to unmarshal opts: %w", err)
}

allDevices := e825Opts.allDevices()
Expand Down Expand Up @@ -239,7 +246,7 @@ func AfterRunPTPCommandE825(data *interface{}, nodeProfile *ptpv1.PtpProfile, co
optsByteArray, _ = json.Marshal(opts)
err = json.Unmarshal(optsByteArray, &e825Opts)
if err != nil {
glog.Error("e825 failed to unmarshal opts: " + err.Error())
return fmt.Errorf("e825 failed to unmarshal opts: %w", err)
}
switch command {
// "gpspipe" is called once the gpspipe process is running (and we can send ublx commands)
Expand Down
8 changes: 7 additions & 1 deletion addons/intel/e830.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,15 @@ func OnPTPConfigChangeE830(_ *interface{}, nodeProfile *ptpv1.PtpProfile) error
if name == pluginNameE830 {
// Parse user-specified config
optsByteArray, _ = json.Marshal(raw)

// Validate configuration before applying
if validationErrors := ValidateE830Opts(optsByteArray); len(validationErrors) > 0 {
return fmt.Errorf("e830 plugin configuration errors: %s", strings.Join(validationErrors, "; "))
}

err = json.Unmarshal(optsByteArray, &opts)
if err != nil {
glog.Error("e830 failed to unmarshal opts: " + err.Error())
return fmt.Errorf("e830 failed to unmarshal opts: %w", err)
}

allDevices := opts.allDevices()
Expand Down
Loading
Loading