-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Process ts2phc events for multi-cards
Signed-off-by: Jack Ding <[email protected]>
- Loading branch information
Showing
5 changed files
with
185 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Copyright 2023 The Cloud Native Events Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//go:build unittests | ||
// +build unittests | ||
|
||
package metrics_test | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/redhat-cne/cloud-event-proxy/plugins/ptp_operator/config" | ||
"github.com/redhat-cne/cloud-event-proxy/plugins/ptp_operator/metrics" | ||
"github.com/redhat-cne/cloud-event-proxy/plugins/ptp_operator/ptp4lconf" | ||
"github.com/redhat-cne/cloud-event-proxy/plugins/ptp_operator/stats" | ||
"github.com/redhat-cne/cloud-event-proxy/plugins/ptp_operator/types" | ||
) | ||
|
||
type metricsTestCase struct { | ||
ptpLog string | ||
} | ||
|
||
var ptp4lConfig = &ptp4lconf.PTP4lConfig{ | ||
Name: "ptp4l.0.config", | ||
Profile: "grandmaster", | ||
Interfaces: []*ptp4lconf.PTPInterface{ | ||
{ | ||
Name: "ens2f0", | ||
PortID: 1, | ||
PortName: "port 1", | ||
Role: 2, | ||
}, | ||
{ | ||
Name: "ens7f0", | ||
PortID: 2, | ||
PortName: "port 3", | ||
Role: 2, | ||
}, | ||
}, | ||
} | ||
|
||
var ptpEventManager = &metrics.PTPEventManager{ | ||
Stats: make(map[types.ConfigName]map[types.IFace]*stats.Stats), | ||
Ptp4lConfigInterfaces: make(map[types.ConfigName]*ptp4lconf.PTP4lConfig), | ||
} | ||
|
||
var testCase = []string{ | ||
"ts2phc[1699929121]:[ts2phc.0.config] ens2f0 nmea_status 0 offset 999999 s0", | ||
"ts2phc[1699929171]:[ts2phc.0.config] ens2fx nmea_status 1 offset 0 s2", | ||
"ts2phc[1699929121]:[ts2phc.0.config] ens7f0 pps_status 0 offset 999999 s0", | ||
"ts2phc[1699929171]:[ts2phc.0.config] ens7fx pps_status 1 offset 0 s2", | ||
"GM[1699929086]:[ts2phc.0.config] ens2f0 T-GM-STATUS s0", | ||
"ts2phc[441664.291]: [ts2phc.0.config] ens2f0 master offset 0 s2 freq -0", | ||
"ts2phc[441664.304]: [ts2phc.0.config] ens7f0 master offset 0 s2 freq +0", | ||
} | ||
|
||
func setup() { | ||
ptpEventManager.AddPTPConfig(types.ConfigName(ptp4lConfig.Name), ptp4lConfig) | ||
|
||
stats_master := stats.NewStats(ptp4lConfig.Name) | ||
stats_master.SetOffsetSource("master") | ||
stats_master.SetProcessName("ts2phc") | ||
stats_master.SetAlias("ens2fx") | ||
|
||
stats_slave := stats.NewStats(ptp4lConfig.Name) | ||
stats_slave.SetOffsetSource("phc") | ||
stats_slave.SetProcessName("phc2sys") | ||
stats_slave.SetLastSyncState("LOCKED") | ||
stats_slave.SetClockClass(0) | ||
|
||
ptpEventManager.Stats[types.ConfigName(ptp4lConfig.Name)] = make(map[types.IFace]*stats.Stats) | ||
ptpEventManager.Stats[types.ConfigName(ptp4lConfig.Name)][types.IFace("master")] = stats_master | ||
ptpEventManager.Stats[types.ConfigName(ptp4lConfig.Name)][types.IFace("CLOCK_REALTIME")] = stats_slave | ||
ptpEventManager.PtpConfigMapUpdates = config.NewLinuxPTPConfUpdate() | ||
} | ||
|
||
func teardown() { | ||
} | ||
|
||
func TestMain(m *testing.M) { | ||
setup() | ||
code := m.Run() | ||
teardown() | ||
os.Exit(code) | ||
} | ||
func Test_ExtractMetrics(t *testing.T) { | ||
for _, tc := range testCase { | ||
ptpEventManager.ExtractMetrics(tc) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters