RDK Documentation (Open Sourced RDK Components)
TuneSmokeTest.cpp
Go to the documentation of this file.
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file
3  * the following copyright and licenses apply:
4  *
5  * Copyright 2022 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 /**
21  * @file TuneSmokeTest.cpp
22  * @brief Tune SmokeTest cases
23  */
24 
25 #include <time.h>
26 #include "AampSmokeTestPlayer.h"
27 #include "TuneSmokeTest.h"
28 
29 extern AampPlayer mAampPlayer;
30 
31 bool SmokeTest::dashPauseState = false;
32 bool SmokeTest::dashFastForwardState = false;
33 bool SmokeTest::dashPlayState = false;
34 bool SmokeTest::dashRewindState = false;
35 bool SmokeTest::hlsPauseState = false;
36 bool SmokeTest::hlsFastForwardState = false;
37 bool SmokeTest::hlsPlayState = false;
38 bool SmokeTest::hlsRewindState = false;
39 bool SmokeTest::livePlayState = false;
40 bool SmokeTest::livePauseState = false;
41 
42 std::vector<std::string> SmokeTest::dashTuneData(0);
43 std::vector<std::string> SmokeTest::hlsTuneData(0);
44 std::vector<std::string> SmokeTest::liveTuneData(0);
45 
46 std::map<std::string, std::string> SmokeTest::smokeTestUrls = std::map<std::string, std::string>();
47 
48 bool SmokeTest::aampTune()
49 {
50  loadSmokeTestUrls();
51  vodTune("Dash");
52  vodTune("Hls");
53  liveTune("Live");
54 
55  return true;
56 }
57 
58 void SmokeTest::loadSmokeTestUrls()
59 {
60 
61  const std::string smokeurlFile("/smoketest.csv");
62  int BUFFER_SIZE = 500;
63  char buffer[BUFFER_SIZE];
64  FILE *fp;
65 
66  if ( (fp = mAampPlayer.getConfigFile(smokeurlFile)) != NULL)
67  {
68  printf("%s:%d: opened smoketest file\n",__FUNCTION__,__LINE__);
69 
70  while(!feof(fp))
71  {
72  if(fgets(buffer, BUFFER_SIZE, fp) != NULL)
73  {
74  buffer[strcspn(buffer, "\n")] = 0;
75  std::string urlData(buffer);
76 
77  std::size_t delimiterPos = urlData.find(",");
78 
79  if(delimiterPos != std::string::npos)
80  {
81  smokeTestUrls[ urlData.substr(0, delimiterPos) ] = urlData.substr(delimiterPos + 1);
82  }
83  }
84  }
85 
86  fclose(fp);
87  }
88 
89 }
90 
91 void SmokeTest::vodTune(const char *stream)
92 {
93  const char *url = NULL;
94  std::string fileName;
95  std::string testFilePath;
96  FILE *fp;
97  time_t initialTime = 0, currentTime = 0;
98  std::map<std::string, std::string>::iterator itr;
99 
100  createTestFilePath(testFilePath);
101  if(strncmp(stream,"Dash",4) == 0)
102  {
103  fileName = testFilePath + "tuneDashStream.txt";
104  itr = smokeTestUrls.find("VOD_DASH");
105 
106  if(itr != smokeTestUrls.end())
107  {
108  url = (itr->second).c_str();
109  }
110 
111  if(url == NULL)
112  {
113  url = "https://cpetestutility.stb.r53.xcal.tv/VideoTestStream/main.mpd";
114  }
115 
116  }
117  else if(strncmp(stream,"Hls",3) == 0)
118  {
119  fileName = testFilePath + "tuneHlsStream.txt";
120  itr = smokeTestUrls.find("VOD_HLS");
121 
122  if(itr != smokeTestUrls.end())
123  {
124  url = (itr->second).c_str();
125  }
126 
127  if(url == NULL)
128  {
129  url = "https://cpetestutility.stb.r53.xcal.tv/VideoTestStream/main.m3u8";
130  }
131  }
132 
133  fp = stdout;
134  stdout = fopen(fileName.c_str(),"w");
135 
136  mAampPlayer.mPlayerInstanceAamp->Tune(url);
137 
138  initialTime = time(NULL);
139 
140  while(1)
141  {
142  sleep(5);
143  if(mAampPlayer.mPlayerInstanceAamp->GetState() == eSTATE_COMPLETE)
144  {
145  printf("%s:%d: Tune sub task started\n",__FUNCTION__,__LINE__);
146  mAampPlayer.mPlayerInstanceAamp->Tune(url);
147  mAampPlayer.mPlayerInstanceAamp->SetRate(0); // To pause
148  mAampPlayer.mPlayerInstanceAamp->SetRate(4); // To fastforward
149  mAampPlayer.mPlayerInstanceAamp->SetRate(1); // To play
150  sleep(20);
151  mAampPlayer.mPlayerInstanceAamp->SetRate(-2); // To rewind
152  sleep(10);
153  mAampPlayer.mPlayerInstanceAamp->Stop();
154  sleep(3);
155 
156  printf("%s:%d: Tune %s completed\n",__FUNCTION__,__LINE__,stream);
157  break;
158  }
159 
160  currentTime = time(NULL);
161  if((currentTime - initialTime) > 1200)
162  {
163  break;
164  }
165  }
166 
167  fclose(stdout);
168  stdout = fp;
169 }
170 
171 void SmokeTest::liveTune(const char *stream)
172 {
173  const char *url = NULL;
174  std::string fileName;
175  std::string testFilePath;
176  FILE *fp;
177 
178  createTestFilePath(testFilePath);
179 
180  url = "https://ll-usw2.akamaized.net/live/disk/sky/DASH-LL-sky.toml/sky.mpd";
181  fileName = testFilePath +"tuneLive.txt";
182 
183  fp = stdout;
184  stdout = fopen(fileName.c_str(),"w");
185 
186  mAampPlayer.mPlayerInstanceAamp->Tune(url);
187  sleep(10);
188  mAampPlayer.mPlayerInstanceAamp->SetRate(0); // To pause
189  mAampPlayer.mPlayerInstanceAamp->SetRate(1); // To play
190  sleep(10);
191  mAampPlayer.mPlayerInstanceAamp->Stop();
192  sleep(5);
193 
194  fclose(stdout);
195  stdout = fp;
196 
197 }
198 
199 bool SmokeTest::createTestFilePath(std::string &filePath)
200 {
201  getFilePath(filePath);
202  DIR *dir = opendir(filePath.c_str());
203  if (!dir)
204  {
205  mkdir(filePath.c_str(), 0777);
206  }
207  else
208  {
209  closedir(dir);
210  }
211 
212  return true;
213 }
214 
215 void SmokeTest::getTuneDetails()
216 {
217  readVodData("Dash");
218  readVodData("Hls");
219  readLiveData("Live");
220 }
221 
222 bool SmokeTest::getFilePath(std::string &filePath)
223 {
224 #ifdef SIMULATOR_BUILD
225  char *ptr = getenv("HOME");
226  if(ptr)
227  {
228  filePath.append(ptr);
229  filePath += "/smoketest/";
230  }
231  else
232  {
233  printf("%s:%d: Path not found \n",__FUNCTION__,__LINE__);
234  return false;
235  }
236 #else
237  filePath = "/opt/smoketest/";
238 #endif
239  return true;
240 }
241 
242 bool SmokeTest::readVodData(const char *stream)
243 {
244  int BUFFER_SIZE = 500;
245  char buffer[BUFFER_SIZE];
246  char *token = NULL;
247  FILE *fp;
248  std::string fileName;
249 
250  if(getFilePath(fileName))
251  {
252  if(strncmp(stream,"Dash",4) == 0)
253  fileName = fileName + "tuneDashStream.txt";
254  else if(strncmp(stream,"Hls",3) == 0)
255  fileName = fileName + "tuneHlsStream.txt";
256 
257  if( fp = fopen(fileName.c_str(), "r"))
258  {
259  while(!feof(fp))
260  {
261  if(fgets(buffer, BUFFER_SIZE, fp) != NULL)
262  {
263 
264  if (strstr(buffer, "IP_AAMP_TUNETIME:") != NULL)
265  {
266  token = strstr(buffer, "IP_AAMP_TUNETIME:");
267  token[strcspn(token, "\n")] = 0;
268 
269  std::stringstream ss(token+17);
270  std::string data;
271 
272  while(std::getline(ss, data, ','))
273  {
274  if(strncmp(stream,"Dash",4) == 0)
275  {
276  SmokeTest::dashTuneData.push_back(data);
277 
278  }
279  else if(strncmp(stream,"Hls",3) == 0)
280  {
281  SmokeTest::hlsTuneData.push_back(data);
282 
283  }
284  }
285  }
286 
287  if (strstr(buffer, "AAMP_EVENT_STATE_CHANGED: PAUSED (6)") != NULL)
288  {
289  if(strncmp(stream,"Dash",4) == 0)
290  dashPauseState = true;
291  else if(strncmp(stream,"Hls",3) == 0)
292  hlsPauseState = true;
293  }
294 
295  if (strstr(buffer, "AAMP_EVENT_SPEED_CHANGED current rate=4") != NULL)
296  {
297  if(strncmp(stream,"Dash",4) == 0)
298  dashFastForwardState = true;
299  else if(strncmp(stream,"Hls",3) == 0)
300  hlsFastForwardState = true;
301  }
302 
303  if (strstr(buffer, "AAMP_EVENT_SPEED_CHANGED current rate=1") != NULL)
304  {
305  if(strncmp(stream,"Dash",4) == 0)
306  dashPlayState = true;
307  else if(strncmp(stream,"Hls",3) == 0)
308  hlsPlayState = true;
309  }
310 
311  if (strstr(buffer, "AAMP_EVENT_SPEED_CHANGED current rate=-2") != NULL)
312  {
313  if(strncmp(stream,"Dash",4) == 0)
314  dashRewindState = true;
315  else if(strncmp(stream,"Hls",3) == 0)
316  hlsRewindState = true;
317 
318  break;
319  }
320 
321  }
322  }
323 
324  fclose(fp);
325  return true;
326  }
327  else
328  {
329  printf("%s:%d: %s file not found \n",__FUNCTION__,__LINE__,stream);
330  return false;
331  }
332  }
333  return false;
334 }
335 
336 bool SmokeTest::readLiveData(const char *stream)
337 {
338  int BUFFER_SIZE = 500;
339  char buffer[BUFFER_SIZE];
340  char *token = NULL;
341  FILE *fp;
342  std::string fileName;
343 
344  if(getFilePath(fileName))
345  {
346  fileName = fileName + "tuneLive.txt";
347 
348  if(fp = fopen(fileName.c_str(), "r"))
349  {
350  while(!feof(fp))
351  {
352  if(fgets(buffer, BUFFER_SIZE, fp) != NULL)
353  {
354  if (strstr(buffer, "IP_TUNETIME:") != NULL)
355  {
356  token = strstr(buffer, "IP_TUNETIME:");
357  token[strcspn(token, "\n")] = 0;
358 
359  std::stringstream ss(token+12);
360  std::string data;
361 
362  while(std::getline(ss, data, ','))
363  {
364  SmokeTest::liveTuneData.push_back(data);
365 
366  }
367  }
368 
369  if (strstr(buffer, "AAMP_EVENT_STATE_CHANGED: PAUSED (6)") != NULL)
370  {
371  livePauseState = true;
372  }
373 
374  if (strstr(buffer, "AAMP_EVENT_SPEED_CHANGED current rate=1") != NULL)
375  {
376  livePlayState = true;
377  }
378  }
379  }
380 
381  fclose(fp);
382  return true;
383  }
384  else
385  {
386  printf("%s:%d: %s file not found \n",__FUNCTION__,__LINE__,stream);
387  return false;
388  }
389  }
390  return false;
391 }
392 
393 /* To test the manifest download start time is less than 7ms(expected)*/
394 TEST(dashTuneTest, ManifestDLStartTime)
395 {
396  if(!SmokeTest::dashTuneData.empty())
397  EXPECT_LE(stoi(SmokeTest::dashTuneData[3]),7);
398 }
399 
400 /* To test the manifest download end time is less than 1s(expected)*/
401 TEST(dashTuneTest, ManifestDLEndTime)
402 {
403  if(!SmokeTest::dashTuneData.empty())
404  EXPECT_LE(stoi(SmokeTest::dashTuneData[4]),1000);
405 }
406 
407 /* To test the manifest download fail count is zero*/
408 TEST(dashTuneTest, ManifestDLFailCount)
409 {
410  if(!SmokeTest::dashTuneData.empty())
411  EXPECT_EQ(stoi(SmokeTest::dashTuneData[5]),0);
412 }
413 
414 /* To test the video playlist download fail count is zero*/
415 TEST(dashTuneTest, VideoPlaylistDLFailCount)
416 {
417  if(!SmokeTest::dashTuneData.empty())
418  EXPECT_EQ(stoi(SmokeTest::dashTuneData[8]),0);
419 }
420 
421 /* To test the audio playlist download fail count is zero*/
422 TEST(dashTuneTest, AudioPlaylistDLFailCount)
423 {
424  if(!SmokeTest::dashTuneData.empty())
425  EXPECT_EQ(stoi(SmokeTest::dashTuneData[11]),0);
426 }
427 
428 /* To test the video init download fail count is zero*/
429 TEST(dashTuneTest, VideoInitDLFailCount)
430 {
431  if(!SmokeTest::dashTuneData.empty())
432  EXPECT_EQ(stoi(SmokeTest::dashTuneData[14]),0);
433 }
434 
435 /* To test the audio init download fail count is zero*/
436 TEST(dashTuneTest, AudioInitDLFailCount)
437 {
438  if(!SmokeTest::dashTuneData.empty())
439  EXPECT_EQ(stoi(SmokeTest::dashTuneData[17]),0);
440 }
441 
442 /* To test the video fragment download fail count is zero*/
443 TEST(dashTuneTest, VideoFragmentDLFailCount)
444 {
445  if(!SmokeTest::dashTuneData.empty())
446  EXPECT_EQ(stoi(SmokeTest::dashTuneData[20]),0);
447 }
448 
449 /* To test the audio fragment download fail count is zero*/
450 TEST(dashTuneTest, AudioFragmentDLFailCount)
451 {
452  if(!SmokeTest::dashTuneData.empty())
453  EXPECT_EQ(stoi(SmokeTest::dashTuneData[24]),0);
454 }
455 
456 /* To test the DRM fail error code is zero*/
457 TEST(dashTuneTest, DrmFailErrorCode)
458 {
459  if(!SmokeTest::dashTuneData.empty())
460  EXPECT_EQ(stoi(SmokeTest::dashTuneData[28]),0);
461 }
462 
463 /* To test the pause state is true*/
464 TEST(dashTuneTest, PauseState)
465 {
466  EXPECT_EQ(SmokeTest::dashPauseState,true);
467 }
468 
469 /* To test the fast forward state is true*/
470 TEST(dashTuneTest, FastForwardState)
471 {
472  EXPECT_EQ(SmokeTest::dashFastForwardState,true);
473 }
474 
475 /* To test the play state is true*/
476 TEST(dashTuneTest, PlayState)
477 {
478  EXPECT_EQ(SmokeTest::dashPlayState,true);
479 }
480 
481 /* To test the rewind state is true*/
482 TEST(dashTuneTest, RewindState)
483 {
484  EXPECT_EQ(SmokeTest::dashRewindState,true);
485 }
486 
487 /* To test the manifest download start time is less than 7ms(expected)*/
488 TEST(hlsTuneTest, ManifestDLStartTime)
489 {
490  if(!SmokeTest::hlsTuneData.empty())
491  EXPECT_LE(stoi(SmokeTest::hlsTuneData[3]),7);
492 }
493 
494 /* To test the manifest download end time is less than 1s(expected)*/
495 TEST(hlsTuneTest, ManifestDLEndTime)
496 {
497  if(!SmokeTest::hlsTuneData.empty())
498  EXPECT_LE(stoi(SmokeTest::hlsTuneData[4]),1000);
499 }
500 
501 /* To test the manifest download fail count is zero*/
502 TEST(hlsTuneTest, ManifestDLFailCount)
503 {
504  if(!SmokeTest::hlsTuneData.empty())
505  EXPECT_EQ(stoi(SmokeTest::hlsTuneData[5]),0);
506 }
507 
508 /* To test the video playlist download fail count is zero*/
509 TEST(hlsTuneTest, VideoPlaylistDLFailCount)
510 {
511  if(!SmokeTest::hlsTuneData.empty())
512  EXPECT_EQ(stoi(SmokeTest::hlsTuneData[8]),0);
513 }
514 
515 /* To test the audio playlist download fail count is zero*/
516 TEST(hlsTuneTest, AudioPlaylistDLFailCount)
517 {
518  if(!SmokeTest::hlsTuneData.empty())
519  EXPECT_EQ(stoi(SmokeTest::hlsTuneData[11]),0);
520 }
521 
522 /* To test the video init download fail count is zero*/
523 TEST(hlsTuneTest, VideoInitDLFailCount)
524 {
525  if(!SmokeTest::hlsTuneData.empty())
526  EXPECT_EQ(stoi(SmokeTest::hlsTuneData[14]),0);
527 }
528 
529 /* To test the audio init download fail count is zero*/
530 TEST(hlsTuneTest, AudioInitDLFailCount)
531 {
532  if(!SmokeTest::hlsTuneData.empty())
533  EXPECT_EQ(stoi(SmokeTest::hlsTuneData[17]),0);
534 }
535 
536 /* To test the video fragment download fail count is zero*/
537 TEST(hlsTuneTest, VideoFragmentDLFailCount)
538 {
539  if(!SmokeTest::hlsTuneData.empty())
540  EXPECT_EQ(stoi(SmokeTest::hlsTuneData[20]),0);
541 }
542 
543 /* To test the audio fragment download fail count is zero*/
544 TEST(hlsTuneTest, AudioFragmentDLFailCount)
545 {
546  if(!SmokeTest::hlsTuneData.empty())
547  EXPECT_EQ(stoi(SmokeTest::hlsTuneData[24]),0);
548 }
549 
550 /* To test the DRM fail error code is zero*/
551 TEST(hlsTuneTest, DrmFailErrorCode)
552 {
553  if(!SmokeTest::hlsTuneData.empty())
554  EXPECT_EQ(stoi(SmokeTest::hlsTuneData[28]),0);
555 }
556 
557 /* To test the pause state is true*/
558 TEST(hlsTuneTest, PauseState)
559 {
560  EXPECT_EQ(SmokeTest::hlsPauseState,true);
561 }
562 
563 /* To test the fast forward state is true*/
564 TEST(hlsTuneTest, FastForwardState)
565 {
566  EXPECT_EQ(SmokeTest::hlsFastForwardState,true);
567 }
568 
569 /* To test the play state is true*/
570 TEST(hlsTuneTest, PlayState)
571 {
572  EXPECT_EQ(SmokeTest::hlsPlayState,true);
573 }
574 
575 /* To test the rewind state is true*/
576 TEST(hlsTuneTest, RewindState)
577 {
578  EXPECT_EQ(SmokeTest::hlsRewindState,true);
579 }
580 
581 /* To test live pause state is true*/
582 TEST(liveTuneTest, PauseState)
583 {
584  EXPECT_EQ(SmokeTest::livePauseState,true);
585 }
586 
587 /* To test live play state is true*/
588 TEST(liveTuneTest, PlayState)
589 {
590  EXPECT_EQ(SmokeTest::livePlayState,true);
591 }
592 
TuneSmokeTest.h
TuneSmokeTest header file.
AampPlayer
Definition: AampSmokeTestPlayer.h:39
PlayerInstanceAAMP::GetState
PrivAAMPState GetState(void)
To get the current AAMP state.
Definition: main_aamp.cpp:1765
PlayerInstanceAAMP::SetRate
void SetRate(float rate, int overshootcorrection=0)
Set playback rate.
Definition: main_aamp.cpp:561
PlayerInstanceAAMP::Tune
void Tune(const char *mainManifestUrl, const char *contentType, bool bFirstAttempt, bool bFinalAttempt, const char *traceUUID, bool audioDecoderStreamSync)
Tune to a URL. DEPRECATED! This is included for backwards compatibility with current Sky AS integrati...
Definition: main_aamp.cpp:312
AampSmokeTestPlayer.h
AampSmokeTestPlayer header file.
PlayerInstanceAAMP::Stop
void Stop(bool sendStateChangeEvent=true)
Stop playback and release resources.
Definition: main_aamp.cpp:282
eSTATE_COMPLETE
@ eSTATE_COMPLETE
Definition: AampEvent.h:169